add update email form on account page

This commit is contained in:
Hongbo Wu
2023-10-02 22:21:50 +08:00
parent c40e64773a
commit ee50529f95
10 changed files with 269 additions and 114 deletions

View File

@ -0,0 +1,45 @@
import { gql } from 'graphql-request'
import { gqlFetcher } from '../networkHelpers'
export interface UpdateEmailInput {
email: string
}
export interface UpdateEmailSuccess {
email: string
verificationEmailSent: boolean
}
interface Response {
updateEmail: UpdateEmailSuccess
}
export async function updateEmailMutation(
input: UpdateEmailInput
): Promise<UpdateEmailSuccess | undefined> {
const mutation = gql`
mutation UpdateEmail($input: UpdateEmailInput!) {
updateEmail(input: $input) {
... on UpdateEmailSuccess {
email
verificationEmailSent
}
... on UpdateEmailError {
errorCodes
}
}
}
`
try {
const data = await gqlFetcher(mutation, {
input,
})
const output = data as Response
return {
email: output.updateEmail.email,
verificationEmailSent: output.updateEmail.verificationEmailSent,
}
} catch (err) {
return undefined
}
}