import HCaptcha from '@hcaptcha/react-hcaptcha' import { zodResolver } from '@hookform/resolvers/zod' import { useRef, useState } from 'react' import { SubmitHandler, useForm } from 'react-hook-form' import { toast } from 'sonner' import { Button, DialogFooter, DialogSection, Form, FormControl, FormField, Input } from 'ui' import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout' import * as z from 'zod' import { InlineLink } from '@/components/ui/InlineLink' import { useEmailUpdateMutation } from '@/data/profile/profile-update-email-mutation' export const GitHubChangeEmailAddress = () => { return (

Email addresses for GitHub identities should be updated through GitHub

  1. Log out of Briven
  2. Change your Primary Email in{' '} GitHub {' '} (your primary email)
  3. Log out of GitHub
  4. Log back into GitHub (with the new, desired email set as primary)
  5. Log back into Briven
) } export const SSOChangeEmailAddress = () => { return (

Email addresses for SSO should be updated through your identity provider

  1. Contact the owner / admin for your team to change your email
) } export const ChangeEmailAddressForm = ({ onClose }: { onClose: () => void }) => { const captchaRef = useRef(null) const [captchaToken, setCaptchaToken] = useState(null) const FormSchema = z.object({ email: z.string().email() }) const form = useForm>({ mode: 'onBlur', reValidateMode: 'onBlur', resolver: zodResolver(FormSchema as any), defaultValues: { email: '' }, }) const { mutate: updateEmail, isPending } = useEmailUpdateMutation({ onSuccess: (_, vars) => { toast.success( `A confirmation email has been sent to ${vars.email}. Please confirm the change within 10 minutes.` ) onClose() }, onError: (error) => { toast.error(`Failed to update email: ${error.message}`) setCaptchaToken(null) captchaRef.current?.resetCaptcha() }, }) const onSubmit: SubmitHandler> = async (values) => { let token = captchaToken if (!token) { const captchaResponse = await captchaRef.current?.execute({ async: true }) token = captchaResponse?.response ?? null } updateEmail({ email: values.email, hcaptchaToken: token ?? null }) } return (
setCaptchaToken(token)} onExpire={() => setCaptchaToken(null)} />
( )} />
) }