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

Function AddEmailForm

@app/client/src/pages/settings/emails.tsx:212–268  ·  view source on GitHub ↗
({ error, setError, onComplete }: AddEmailFormProps)

Source from the content-addressed store, hash-verified

210}
211
212function AddEmailForm({ error, setError, onComplete }: AddEmailFormProps) {
213 const [form] = useForm();
214 const [addEmail] = useAddEmailMutation();
215 const handleSubmit = useCallback(
216 async (values: Store) => {
217 try {
218 setError(null);
219 await addEmail({ variables: { email: values.email } });
220 onComplete();
221 } catch (e) {
222 setError(e);
223 }
224 },
225 [addEmail, onComplete, setError]
226 );
227 const code = getCodeFromError(error);
228 return (
229 <Form {...formItemLayout} form={form} onFinish={handleSubmit}>
230 <Form.Item
231 label="New email"
232 name="email"
233 rules={[
234 {
235 required: true,
236 message: "Please enter an email address",
237 },
238 ]}
239 >
240 <Input data-cy="settingsemails-input-email" />
241 </Form.Item>
242 {error ? (
243 <Form.Item>
244 <Alert
245 type="error"
246 message={`Error adding email`}
247 description={
248 <span>
249 {extractError(error).message}
250 {code ? (
251 <span>
252 {" "}
253 (Error code: <code>ERR_{code}</code>)
254 </span>
255 ) : null}
256 </span>
257 }
258 />
259 </Form.Item>
260 ) : null}
261 <Form.Item {...tailFormItemLayout}>
262 <Button htmlType="submit" data-cy="settingsemails-button-submit">
263 Add email
264 </Button>
265 </Form.Item>
266 </Form>
267 );
268}

Callers

nothing calls this directly

Calls 3

getCodeFromErrorFunction · 0.90
extractErrorFunction · 0.90
addEmailFunction · 0.85

Tested by

no test coverage detected