MCPcopy
hub / github.com/graphile/starter / ProfileSettingsForm

Function ProfileSettingsForm

@app/client/src/pages/settings/index.tsx:60–168  ·  view source on GitHub ↗
({
  user,
  error,
  setError,
}: ProfileSettingsFormProps)

Source from the content-addressed store, hash-verified

58}
59
60function ProfileSettingsForm({
61 user,
62 error,
63 setError,
64}: ProfileSettingsFormProps) {
65 const [form] = useForm();
66 const [updateUser] = useUpdateUserMutation();
67 const [success, setSuccess] = useState(false);
68
69 const handleSubmit = useCallback(
70 async (values: Store) => {
71 setSuccess(false);
72 setError(null);
73 try {
74 await updateUser({
75 variables: {
76 id: user.id,
77 patch: {
78 username: values.username,
79 name: values.name,
80 },
81 },
82 });
83 setError(null);
84 setSuccess(true);
85 } catch (e) {
86 const errcode = getCodeFromError(e);
87 if (errcode === "23505") {
88 form.setFields([
89 {
90 name: "username",
91 value: form.getFieldValue("username"),
92 errors: [
93 "This username is already in use, please pick a different name",
94 ],
95 },
96 ]);
97 } else {
98 setError(e);
99 }
100 }
101 },
102 [setError, updateUser, user.id, form]
103 );
104
105 const code = getCodeFromError(error);
106 return (
107 <div>
108 <PageHeader title="Edit profile" />
109 <Form
110 {...formItemLayout}
111 form={form}
112 onFinish={handleSubmit}
113 initialValues={{ name: user.name, username: user.username }}
114 >
115 <Form.Item
116 label="Name"
117 name="name"

Callers

nothing calls this directly

Calls 2

getCodeFromErrorFunction · 0.90
extractErrorFunction · 0.90

Tested by

no test coverage detected