@@ -15,44 +15,42 @@ import { graphql } from "../../gql";
1515import  {  graphqlRequest  }  from  "../../graphql" ; 
1616
1717const  ADD_EMAIL_MUTATION  =  graphql ( /* GraphQL */  ` 
18-   mutation AddEmail($userId: ID !, $email : String!) { 
19-     addEmail (input: { userId : $userId, email : $email  }) { 
18+   mutation AddEmail($email: String !, $language : String!) { 
19+     startEmailAuthentication (input: { email : $email, language : $language  }) { 
2020      status 
2121      violations 
22-       email  { 
22+       authentication  { 
2323        id 
24-         ...UserEmail_email 
2524      } 
2625    } 
2726  } 
2827` ) ; 
2928
3029const  AddEmailForm : React . FC < { 
31-   userId : string ; 
3230  onAdd : ( id : string )  =>  Promise < void > ; 
33- } >  =  ( {  userId ,   onAdd } )  =>  { 
34-   const  {  t }  =  useTranslation ( ) ; 
31+ } >  =  ( {  onAdd } )  =>  { 
32+   const  {  t,  i18n  }  =  useTranslation ( ) ; 
3533  const  queryClient  =  useQueryClient ( ) ; 
3634  const  addEmail  =  useMutation ( { 
37-     mutationFn : ( {  userId ,  email  } : {  userId : string ;  email : string  } )  => 
35+     mutationFn : ( {  email ,  language  } : {  email : string ;  language : string  } )  => 
3836      graphqlRequest ( { 
3937        query : ADD_EMAIL_MUTATION , 
40-         variables : {  userId ,  email  } , 
38+         variables : {  email ,  language  } , 
4139      } ) , 
4240    onSuccess : async  ( data )  =>  { 
4341      queryClient . invalidateQueries ( {  queryKey : [ "userEmails" ]  } ) ; 
4442
4543      // Don't clear the form if the email was invalid or already exists 
46-       if  ( data . addEmail . status  !==  "ADDED " )  { 
44+       if  ( data . startEmailAuthentication . status  !==  "STARTED " )  { 
4745        return ; 
4846      } 
4947
50-       if  ( ! data . addEmail . email ?. id )  { 
48+       if  ( ! data . startEmailAuthentication . authentication ?. id )  { 
5149        throw  new  Error ( "Unexpected response from server" ) ; 
5250      } 
5351
5452      // Call the onAdd callback 
55-       await  onAdd ( data . addEmail . email ?. id ) ; 
53+       await  onAdd ( data . startEmailAuthentication . authentication ?. id ) ; 
5654    } , 
5755  } ) ; 
5856
@@ -63,34 +61,35 @@ const AddEmailForm: React.FC<{
6361
6462    const  formData  =  new  FormData ( e . currentTarget ) ; 
6563    const  email  =  formData . get ( "input" )  as  string ; 
66-     addEmail . mutate ( {  userId ,  email  } ) ; 
64+     addEmail . mutate ( {  email ,   language :  i18n . languages [ 0 ]  } ) ; 
6765  } ; 
6866
69-   const  status  =  addEmail . data ?. addEmail . status  ??  null ; 
70-   const  violations  =  addEmail . data ?. addEmail . violations  ??  [ ] ; 
67+   const  status  =  addEmail . data ?. startEmailAuthentication . status  ??  null ; 
68+   const  violations  =  addEmail . data ?. startEmailAuthentication . violations  ??  [ ] ; 
7169
7270  return  ( 
7371    < EditInPlace 
7472      onSave = { handleSubmit } 
7573      required 
7674      type = "email" 
77-       serverInvalid = { 
78-         status  ===  "INVALID"  ||  status  ===  "EXISTS"  ||  status  ===  "DENIED" 
79-       } 
75+       serverInvalid = { ! ! status  &&  status  !==  "STARTED" } 
8076      label = { t ( "frontend.add_email_form.email_field_label" ) } 
8177      helpLabel = { t ( "frontend.add_email_form.email_field_help" ) } 
8278      saveButtonLabel = { t ( "action.save" ) } 
8379      savingLabel = { t ( "common.saving" ) } 
8480      savedLabel = { t ( "common.saved" ) } 
8581      cancelButtonLabel = { t ( "action.cancel" ) } 
8682    > 
87-       < ErrorMessage  match = "typeMismatch"  forceMatch = { status  ===  "INVALID" } > 
83+       < ErrorMessage 
84+         match = "typeMismatch" 
85+         forceMatch = { status  ===  "INVALID_EMAIL_ADDRESS" } 
86+       > 
8887        { t ( "frontend.add_email_form.email_invalid_error" ) } 
8988      </ ErrorMessage > 
9089
91-       { status  ===  "EXISTS "  &&  ( 
90+       { status  ===  "IN_USE "  &&  ( 
9291        < ErrorMessage > 
93-           { t ( "frontend.add_email_form.email_exists_error " ) } 
92+           { t ( "frontend.add_email_form.email_in_use_error " ) } 
9493        </ ErrorMessage > 
9594      ) } 
9695
0 commit comments