diff --git a/src/locales/en.po b/src/locales/en.po index 065f6969..97613b78 100644 --- a/src/locales/en.po +++ b/src/locales/en.po @@ -446,7 +446,7 @@ msgstr "Budget" msgid "Business name" msgstr "Business name" -#: src/validation/RegistrationSchema.tsx:14 +#: src/validation/RegistrationSchema.tsx:21 msgid "Business name is required" msgstr "Business name is required" @@ -454,7 +454,7 @@ msgstr "Business name is required" msgid "Business website" msgstr "Business website" -#: src/validation/RegistrationSchema.tsx:16 +#: src/validation/RegistrationSchema.tsx:23 msgid "Business Website is required" msgstr "Business Website is required" @@ -956,7 +956,7 @@ msgstr "Documentation can be found <0>here on how to use the API." msgid "Domain" msgstr "Domain" -#: src/validation/RegistrationSchema.tsx:34 +#: src/validation/RegistrationSchema.tsx:41 msgid "Domain is required" msgstr "Domain is required" @@ -964,7 +964,7 @@ msgstr "Domain is required" #~ msgid "Domain must match the email domain" #~ msgstr "Domain must match the email domain" -#: src/validation/RegistrationSchema.tsx:35 +#: src/validation/RegistrationSchema.tsx:42 msgid "Domain must not contain any whitespace" msgstr "Domain must not contain any whitespace" @@ -1008,11 +1008,10 @@ msgstr "Edit ad" #: src/auth/registration/BrowserForm.tsx:24 #: src/auth/views/Login.tsx:43 #: src/auth/views/MagicLink.tsx:74 -#: src/user/settings/UserForm.tsx:52 msgid "Email" msgstr "Email" -#: src/validation/UserSchema.tsx:7 +#: src/validation/RegistrationSchema.tsx:12 msgid "Email address is required" msgstr "Email address is required" @@ -1072,6 +1071,10 @@ msgstr "Failed to Fetch" msgid "Failed to load image" msgstr "Failed to load image" +#: src/user/settings/UserForm.tsx:41 +msgid "Failed to update profile: {0}" +msgstr "Failed to update profile: {0}" + #: src/components/Assets/hooks/useUploadFile.ts:146 msgid "Failed to upload image" msgstr "Failed to upload image" @@ -1142,11 +1145,12 @@ msgstr "Full Landing Page URL" msgid "Full name" msgstr "Full name" -#: src/user/settings/UserForm.tsx:66 +#: src/user/settings/UserForm.tsx:68 msgid "Full Name" msgstr "Full Name" -#: src/validation/UserSchema.tsx:9 +#: src/validation/RegistrationSchema.tsx:14 +#: src/validation/UserSchema.tsx:6 msgid "Full name is required" msgstr "Full name is required" @@ -1720,7 +1724,7 @@ msgid "Other source" msgstr "Other source" #: src/auth/views/Login.tsx:51 -#: src/user/settings/UserForm.tsx:58 +#: src/user/settings/UserForm.tsx:74 msgid "Password" msgstr "Password" @@ -1773,16 +1777,16 @@ msgstr "Please confirm your account’s new private key:" msgid "Please enter a username and password" msgstr "Please enter a username and password" -#: src/validation/RegistrationSchema.tsx:38 +#: src/validation/RegistrationSchema.tsx:45 msgid "Please enter a valid domain, for example: brave.com" msgstr "Please enter a valid domain, for example: brave.com" -#: src/validation/UserSchema.tsx:8 +#: src/validation/RegistrationSchema.tsx:13 msgid "Please enter a valid email address" msgstr "Please enter a valid email address" #: src/validation/CreativeSchema.tsx:19 -#: src/validation/RegistrationSchema.tsx:21 +#: src/validation/RegistrationSchema.tsx:28 msgid "Please enter a valid URL, for example https://brave.com" msgstr "Please enter a valid URL, for example https://brave.com" @@ -1794,11 +1798,11 @@ msgstr "Please enter a valid URL, for example https://brave.com/product/*" msgid "Please enter an email." msgstr "Please enter an email." -#: src/validation/RegistrationSchema.tsx:52 +#: src/validation/RegistrationSchema.tsx:59 msgid "Please let us know how you heard about Brave Ads" msgstr "Please let us know how you heard about Brave Ads" -#: src/validation/RegistrationSchema.tsx:24 +#: src/validation/RegistrationSchema.tsx:31 msgid "Please let us know why you're interested in Brave Ads" msgstr "Please let us know why you're interested in Brave Ads" @@ -1818,7 +1822,7 @@ msgstr "Please refresh the page to try again, or email <0/> for assistance." msgid "Please see our <0>Advertiser Privacy Policy and <1>Terms of Service applicable to Brave Ads." msgstr "Please see our <0>Advertiser Privacy Policy and <1>Terms of Service applicable to Brave Ads." -#: src/validation/RegistrationSchema.tsx:57 +#: src/validation/RegistrationSchema.tsx:64 msgid "Please specify how you heard about Brave Ads" msgstr "Please specify how you heard about Brave Ads" @@ -1875,8 +1879,8 @@ msgstr "Pricing type must be CPM, CPC, or CPSV" msgid "Primary region of business" msgstr "Primary region of business" -#: src/validation/RegistrationSchema.tsx:42 -#: src/validation/RegistrationSchema.tsx:45 +#: src/validation/RegistrationSchema.tsx:49 +#: src/validation/RegistrationSchema.tsx:52 msgid "Primary region of business is required" msgstr "Primary region of business is required" @@ -1904,7 +1908,7 @@ msgstr "Profile" msgid "Profile API Key" msgstr "Profile API Key" -#: src/user/settings/UserForm.tsx:36 +#: src/user/settings/UserForm.tsx:46 msgid "Profile Details" msgstr "Profile Details" @@ -2448,7 +2452,7 @@ msgstr "Unable to download CSV" msgid "Unable to get campaign information for ad" msgstr "Unable to get campaign information for ad" -#: src/user/settings/UserForm.tsx:24 +#: src/user/settings/UserForm.tsx:31 msgid "Unable to get profile information" msgstr "Unable to get profile information" @@ -2617,11 +2621,11 @@ msgstr "We value your feedback and would love to hear your thoughts on your rece #~ msgid "We've updated our reporting view" #~ msgstr "We've updated our reporting view" -#: src/validation/RegistrationSchema.tsx:17 +#: src/validation/RegistrationSchema.tsx:24 msgid "Website must not contain any whitespace" msgstr "Website must not contain any whitespace" -#: src/validation/RegistrationSchema.tsx:18 +#: src/validation/RegistrationSchema.tsx:25 msgid "Website must start with https://" msgstr "Website must start with https://" diff --git a/src/locales/es.po b/src/locales/es.po index fcffd3a0..7654d309 100644 --- a/src/locales/es.po +++ b/src/locales/es.po @@ -451,7 +451,7 @@ msgstr "Presupuesto" msgid "Business name" msgstr "Nombre de la empresa" -#: src/validation/RegistrationSchema.tsx:14 +#: src/validation/RegistrationSchema.tsx:21 msgid "Business name is required" msgstr "Se requiere el nombre de la empresa." @@ -459,7 +459,7 @@ msgstr "Se requiere el nombre de la empresa." msgid "Business website" msgstr "Sitio web de la empresa" -#: src/validation/RegistrationSchema.tsx:16 +#: src/validation/RegistrationSchema.tsx:23 msgid "Business Website is required" msgstr "Se requiere el sitio web de la empresa." @@ -961,7 +961,7 @@ msgstr "Puede encontrar documentación <0>aquí sobre cómo usar la API." msgid "Domain" msgstr "Dominio" -#: src/validation/RegistrationSchema.tsx:34 +#: src/validation/RegistrationSchema.tsx:41 msgid "Domain is required" msgstr "Se requiere dominio" @@ -969,7 +969,7 @@ msgstr "Se requiere dominio" #~ msgid "Domain must match the email domain" #~ msgstr "Domain must match the email domain" -#: src/validation/RegistrationSchema.tsx:35 +#: src/validation/RegistrationSchema.tsx:42 msgid "Domain must not contain any whitespace" msgstr "El dominio no debe contener espacios en blanco" @@ -1013,11 +1013,10 @@ msgstr "Editar anuncio" #: src/auth/registration/BrowserForm.tsx:24 #: src/auth/views/Login.tsx:43 #: src/auth/views/MagicLink.tsx:74 -#: src/user/settings/UserForm.tsx:52 msgid "Email" msgstr "Correo electrónico" -#: src/validation/UserSchema.tsx:7 +#: src/validation/RegistrationSchema.tsx:12 msgid "Email address is required" msgstr "Se requiere una dirección de correo electrónico" @@ -1077,6 +1076,10 @@ msgstr "Error al recuperar" msgid "Failed to load image" msgstr "Error al cargar la imagen " +#: src/user/settings/UserForm.tsx:41 +msgid "Failed to update profile: {0}" +msgstr "" + #: src/components/Assets/hooks/useUploadFile.ts:146 msgid "Failed to upload image" msgstr "Error al subir la imagen" @@ -1147,11 +1150,12 @@ msgstr "URL de la página de destino completa" msgid "Full name" msgstr "Nombre completo" -#: src/user/settings/UserForm.tsx:66 +#: src/user/settings/UserForm.tsx:68 msgid "Full Name" msgstr "Nombre completo" -#: src/validation/UserSchema.tsx:9 +#: src/validation/RegistrationSchema.tsx:14 +#: src/validation/UserSchema.tsx:6 msgid "Full name is required" msgstr "Se requiere el nombre completo" @@ -1725,7 +1729,7 @@ msgid "Other source" msgstr "Otra fuente" #: src/auth/views/Login.tsx:51 -#: src/user/settings/UserForm.tsx:58 +#: src/user/settings/UserForm.tsx:74 msgid "Password" msgstr "Contraseña" @@ -1778,16 +1782,16 @@ msgstr "Por favor, confirme la nueva clave privada de su cuenta:" msgid "Please enter a username and password" msgstr "Por favor, introduzca un nombre de usuario y contraseña" -#: src/validation/RegistrationSchema.tsx:38 +#: src/validation/RegistrationSchema.tsx:45 msgid "Please enter a valid domain, for example: brave.com" msgstr "Por favor, introduzca un dominio válido, por ejemplo: brave.com" -#: src/validation/UserSchema.tsx:8 +#: src/validation/RegistrationSchema.tsx:13 msgid "Please enter a valid email address" msgstr "Por favor, introduzca una dirección de correo electrónico válida" #: src/validation/CreativeSchema.tsx:19 -#: src/validation/RegistrationSchema.tsx:21 +#: src/validation/RegistrationSchema.tsx:28 msgid "Please enter a valid URL, for example https://brave.com" msgstr "Por favor, introduzca una URL válida, por ejemplo, https://brave.com" @@ -1799,11 +1803,11 @@ msgstr "Por favor, introduzca una URL válida, por ejemplo, https://brave.com/pr msgid "Please enter an email." msgstr "Por favor, introduzca un correo electrónico." -#: src/validation/RegistrationSchema.tsx:52 +#: src/validation/RegistrationSchema.tsx:59 msgid "Please let us know how you heard about Brave Ads" msgstr "Por favor, indíquenos cómo se enteró de Brave Ads" -#: src/validation/RegistrationSchema.tsx:24 +#: src/validation/RegistrationSchema.tsx:31 msgid "Please let us know why you're interested in Brave Ads" msgstr "Por favor, indíquenos por qué está interesado(a) en Brave Ads" @@ -1823,7 +1827,7 @@ msgstr "Por favor, actualice la página para volver a intentarlo o envíe un cor msgid "Please see our <0>Advertiser Privacy Policy and <1>Terms of Service applicable to Brave Ads." msgstr "Consulte nuestra <0>Política de privacidad del anunciante y <1>Términos de servicio aplicables a Brave Ads." -#: src/validation/RegistrationSchema.tsx:57 +#: src/validation/RegistrationSchema.tsx:64 msgid "Please specify how you heard about Brave Ads" msgstr "Por favor, especifique cómo se enteró de Brave Ads" @@ -1880,8 +1884,8 @@ msgstr "El tipo de precio debe ser CPM, CPC o CPSV" msgid "Primary region of business" msgstr "Región principal de la empresa" -#: src/validation/RegistrationSchema.tsx:42 -#: src/validation/RegistrationSchema.tsx:45 +#: src/validation/RegistrationSchema.tsx:49 +#: src/validation/RegistrationSchema.tsx:52 msgid "Primary region of business is required" msgstr "Se requiere la región principal de la empresa" @@ -1909,7 +1913,7 @@ msgstr "Perfil" msgid "Profile API Key" msgstr "Clave API del perfil" -#: src/user/settings/UserForm.tsx:36 +#: src/user/settings/UserForm.tsx:46 msgid "Profile Details" msgstr "Detalles del perfil" @@ -2453,7 +2457,7 @@ msgstr "No se puede descargar CSV" msgid "Unable to get campaign information for ad" msgstr "No se puede obtener la información de la campaña para el anuncio" -#: src/user/settings/UserForm.tsx:24 +#: src/user/settings/UserForm.tsx:31 msgid "Unable to get profile information" msgstr "No se puede obtener información del perfil" @@ -2622,11 +2626,11 @@ msgstr "Valoramos sus comentarios y nos encantaría conocer su opinión sobre su #~ msgid "We've updated our reporting view" #~ msgstr "We've updated our reporting view" -#: src/validation/RegistrationSchema.tsx:17 +#: src/validation/RegistrationSchema.tsx:24 msgid "Website must not contain any whitespace" msgstr "El sitio web no debe contener ningún espacio en blanco" -#: src/validation/RegistrationSchema.tsx:18 +#: src/validation/RegistrationSchema.tsx:25 msgid "Website must start with https://" msgstr "El sitio web debe comenzar con https://" diff --git a/src/locales/pt.po b/src/locales/pt.po index 99008855..971539da 100644 --- a/src/locales/pt.po +++ b/src/locales/pt.po @@ -451,7 +451,7 @@ msgstr "Orçamento" msgid "Business name" msgstr "Nome da Empresa" -#: src/validation/RegistrationSchema.tsx:14 +#: src/validation/RegistrationSchema.tsx:21 msgid "Business name is required" msgstr "O nome da empresa é obrigatório" @@ -459,7 +459,7 @@ msgstr "O nome da empresa é obrigatório" msgid "Business website" msgstr "Site da Empresa" -#: src/validation/RegistrationSchema.tsx:16 +#: src/validation/RegistrationSchema.tsx:23 msgid "Business Website is required" msgstr "O site da empresa é obrigatório" @@ -961,7 +961,7 @@ msgstr "A documentação sobre como utilizar a API pode ser encontrada <0>aquiAdvertiser Privacy Policy and <1>Terms of Service applicable to Brave Ads." msgstr "Por favor, consulte nossa <0>Política de Privacidade do Anunciante e <1>Termos de Serviço que se aplicam ao Brave Ads." -#: src/validation/RegistrationSchema.tsx:57 +#: src/validation/RegistrationSchema.tsx:64 msgid "Please specify how you heard about Brave Ads" msgstr "Por favor, nos diga como você ficou sabendo sobre o Brave Ads" @@ -1880,8 +1884,8 @@ msgstr "O tipo de preço deve ser CPM, CPC ou CPSV" msgid "Primary region of business" msgstr "Principal região de negócios" -#: src/validation/RegistrationSchema.tsx:42 -#: src/validation/RegistrationSchema.tsx:45 +#: src/validation/RegistrationSchema.tsx:49 +#: src/validation/RegistrationSchema.tsx:52 msgid "Primary region of business is required" msgstr "A principal região de negócios é obrigatória" @@ -1909,7 +1913,7 @@ msgstr "Perfil" msgid "Profile API Key" msgstr "Chave de API do Perfil" -#: src/user/settings/UserForm.tsx:36 +#: src/user/settings/UserForm.tsx:46 msgid "Profile Details" msgstr "Detalhes do Perfil" @@ -2453,7 +2457,7 @@ msgstr "Não foi possível baixar o CSV" msgid "Unable to get campaign information for ad" msgstr "Não foi possível obter informações da campanha para o anúncio" -#: src/user/settings/UserForm.tsx:24 +#: src/user/settings/UserForm.tsx:31 msgid "Unable to get profile information" msgstr "Não foi possível obter informações do perfil" @@ -2622,11 +2626,11 @@ msgstr "Valorizamos seu feedback e adoraríamos ouvir suas opiniões sobre sua e #~ msgid "We've updated our reporting view" #~ msgstr "We've updated our reporting view" -#: src/validation/RegistrationSchema.tsx:17 +#: src/validation/RegistrationSchema.tsx:24 msgid "Website must not contain any whitespace" msgstr "O site não deve conter espaços em branco" -#: src/validation/RegistrationSchema.tsx:18 +#: src/validation/RegistrationSchema.tsx:25 msgid "Website must start with https://" msgstr "O site deve começar com https://" diff --git a/src/locales/test.po b/src/locales/test.po index d8cef6d3..46d6d1eb 100644 --- a/src/locales/test.po +++ b/src/locales/test.po @@ -426,7 +426,7 @@ msgstr "" msgid "Business name" msgstr "" -#: src/validation/RegistrationSchema.tsx:14 +#: src/validation/RegistrationSchema.tsx:21 msgid "Business name is required" msgstr "" @@ -434,7 +434,7 @@ msgstr "" msgid "Business website" msgstr "" -#: src/validation/RegistrationSchema.tsx:16 +#: src/validation/RegistrationSchema.tsx:23 msgid "Business Website is required" msgstr "" @@ -920,7 +920,7 @@ msgstr "" msgid "Domain" msgstr "" -#: src/validation/RegistrationSchema.tsx:34 +#: src/validation/RegistrationSchema.tsx:41 msgid "Domain is required" msgstr "" @@ -928,7 +928,7 @@ msgstr "" #~ msgid "Domain must match the email domain" #~ msgstr "" -#: src/validation/RegistrationSchema.tsx:35 +#: src/validation/RegistrationSchema.tsx:42 msgid "Domain must not contain any whitespace" msgstr "" @@ -972,11 +972,10 @@ msgstr "" #: src/auth/registration/BrowserForm.tsx:24 #: src/auth/views/Login.tsx:43 #: src/auth/views/MagicLink.tsx:74 -#: src/user/settings/UserForm.tsx:52 msgid "Email" msgstr "" -#: src/validation/UserSchema.tsx:7 +#: src/validation/RegistrationSchema.tsx:12 msgid "Email address is required" msgstr "" @@ -1036,6 +1035,10 @@ msgstr "" msgid "Failed to load image" msgstr "" +#: src/user/settings/UserForm.tsx:41 +msgid "Failed to update profile: {0}" +msgstr "" + #: src/components/Assets/hooks/useUploadFile.ts:146 msgid "Failed to upload image" msgstr "" @@ -1098,11 +1101,12 @@ msgstr "" msgid "Full name" msgstr "" -#: src/user/settings/UserForm.tsx:66 +#: src/user/settings/UserForm.tsx:68 msgid "Full Name" msgstr "" -#: src/validation/UserSchema.tsx:9 +#: src/validation/RegistrationSchema.tsx:14 +#: src/validation/UserSchema.tsx:6 msgid "Full name is required" msgstr "" @@ -1648,7 +1652,7 @@ msgid "Other source" msgstr "" #: src/auth/views/Login.tsx:51 -#: src/user/settings/UserForm.tsx:58 +#: src/user/settings/UserForm.tsx:74 msgid "Password" msgstr "" @@ -1701,16 +1705,16 @@ msgstr "" msgid "Please enter a username and password" msgstr "" -#: src/validation/RegistrationSchema.tsx:38 +#: src/validation/RegistrationSchema.tsx:45 msgid "Please enter a valid domain, for example: brave.com" msgstr "" -#: src/validation/UserSchema.tsx:8 +#: src/validation/RegistrationSchema.tsx:13 msgid "Please enter a valid email address" msgstr "" #: src/validation/CreativeSchema.tsx:19 -#: src/validation/RegistrationSchema.tsx:21 +#: src/validation/RegistrationSchema.tsx:28 msgid "Please enter a valid URL, for example https://brave.com" msgstr "" @@ -1722,11 +1726,11 @@ msgstr "" msgid "Please enter an email." msgstr "" -#: src/validation/RegistrationSchema.tsx:52 +#: src/validation/RegistrationSchema.tsx:59 msgid "Please let us know how you heard about Brave Ads" msgstr "" -#: src/validation/RegistrationSchema.tsx:24 +#: src/validation/RegistrationSchema.tsx:31 msgid "Please let us know why you're interested in Brave Ads" msgstr "" @@ -1738,7 +1742,7 @@ msgstr "" msgid "Please see our <0>Advertiser Privacy Policy and <1>Terms of Service applicable to Brave Ads." msgstr "" -#: src/validation/RegistrationSchema.tsx:57 +#: src/validation/RegistrationSchema.tsx:64 msgid "Please specify how you heard about Brave Ads" msgstr "" @@ -1795,8 +1799,8 @@ msgstr "" msgid "Primary region of business" msgstr "" -#: src/validation/RegistrationSchema.tsx:42 -#: src/validation/RegistrationSchema.tsx:45 +#: src/validation/RegistrationSchema.tsx:49 +#: src/validation/RegistrationSchema.tsx:52 msgid "Primary region of business is required" msgstr "" @@ -1820,7 +1824,7 @@ msgstr "" msgid "Profile API Key" msgstr "" -#: src/user/settings/UserForm.tsx:36 +#: src/user/settings/UserForm.tsx:46 msgid "Profile Details" msgstr "" @@ -2312,7 +2316,7 @@ msgstr "" msgid "Unable to get campaign information for ad" msgstr "" -#: src/user/settings/UserForm.tsx:24 +#: src/user/settings/UserForm.tsx:31 msgid "Unable to get profile information" msgstr "" @@ -2477,11 +2481,11 @@ msgstr "" #~ msgid "We've updated our reporting view" #~ msgstr "" -#: src/validation/RegistrationSchema.tsx:17 +#: src/validation/RegistrationSchema.tsx:24 msgid "Website must not contain any whitespace" msgstr "" -#: src/validation/RegistrationSchema.tsx:18 +#: src/validation/RegistrationSchema.tsx:25 msgid "Website must start with https://" msgstr "" diff --git a/src/user/settings/UserForm.tsx b/src/user/settings/UserForm.tsx index 66ef7e67..3098186b 100644 --- a/src/user/settings/UserForm.tsx +++ b/src/user/settings/UserForm.tsx @@ -1,24 +1,31 @@ -import { Stack } from "@mui/material"; -import { useState } from "react"; +import { ReactNode, useState } from "react"; import { useUser } from "@/auth/hooks/queries/useUser"; import { CardContainer } from "@/components/Card/CardContainer"; import { Form, Formik, FormikValues } from "formik"; import { FormikTextField } from "@/form/FormikHelpers"; import { ErrorDetail } from "@/components/Error/ErrorDetail"; import { UserSchema } from "@/validation/UserSchema"; -import _ from "lodash"; import { FormikSubmitButton } from "@/form/FormikButton"; import { useTrackMatomoEvent } from "@/hooks/useTrackWithMatomo"; import { msg, Trans } from "@lingui/macro"; import { useLingui } from "@lingui/react"; import { UpdateUserDocument } from "@/graphql-client/graphql"; import { useMutation } from "@apollo/client"; +import { Snackbar, Stack } from "@mui/material"; + +interface UserFormValues { + fullName: string; + password?: string; +} export function UserForm() { const user = useUser(); const { trackMatomoEvent } = useTrackMatomoEvent(); const { _: lingui } = useLingui(); - const [initialVals, setInitialVals] = useState(user); + const [initialVals, setInitialVals] = useState({ + fullName: user.fullName ?? "", + }); + const [errorMessage, setErrorMessage] = useState(null); if (!user.userId) { const details = msg`Unable to get profile information`; @@ -30,6 +37,9 @@ export function UserForm() { trackMatomoEvent("user", "update"); setInitialVals(user.updateUser); }, + onError(err) { + setErrorMessage(Failed to update profile: {err.message}); + }, }); return ( @@ -40,17 +50,23 @@ export function UserForm() { onSubmit={(v, { setSubmitting }: FormikValues) => { setSubmitting(true); updateUser({ - variables: { input: { id: user.userId, ..._.omit(v, ["userId"]) } }, + variables: { + input: { + id: user.userId, + fullName: v.fullName, + password: v.password, + }, + }, }).finally(() => setSubmitting(false)); }} validationSchema={UserSchema()} >
- + - - - + + setErrorMessage(null)} + autoHideDuration={10_000} /> - diff --git a/src/validation/RegistrationSchema.tsx b/src/validation/RegistrationSchema.tsx index 78aed7e4..163d3688 100644 --- a/src/validation/RegistrationSchema.tsx +++ b/src/validation/RegistrationSchema.tsx @@ -1,12 +1,19 @@ import { object, string } from "yup"; import { t } from "@lingui/macro"; -import { UserSchema } from "@/validation/UserSchema"; const SimpleUrlRegexp = /https:\/\/.+\.[a-zA-Z]{2,}\/?.*/g; const NoSpacesRegex = /^\S*$/; const HttpsRegex = /^https:\/\//; const DomainRegex = /^(?!-)[A-Za-z0-9-]+([-.][a-z0-9]+)*\.[A-Za-z]{2,}$/; +const UserSchema = () => + object().shape({ + email: string() + .required(t`Email address is required`) + .email(t`Please enter a valid email address`), + fullName: string().required(t`Full name is required`), + }); + const BrowserRegistrationSchema = () => object().shape({ user: UserSchema(), diff --git a/src/validation/UserSchema.test.ts b/src/validation/UserSchema.test.ts index 7e9459f8..a21726f9 100644 --- a/src/validation/UserSchema.test.ts +++ b/src/validation/UserSchema.test.ts @@ -2,7 +2,6 @@ import { UserSchema } from "./UserSchema"; import { produce } from "immer"; const validUser = { - email: "test@brave.com", fullName: "Test User", }; @@ -10,9 +9,9 @@ it("should pass on a valid object", () => { UserSchema().validateSync(validUser); }); -it("should fail if the campaign format is invalid", () => { +it("should fail if the full name is invalid", () => { const c = produce(validUser, (draft) => { - draft.email = ""; + draft.fullName = ""; }); expect(() => UserSchema().validateSync(c)).toThrowError(); diff --git a/src/validation/UserSchema.tsx b/src/validation/UserSchema.tsx index 837d6dc9..e7ea130e 100644 --- a/src/validation/UserSchema.tsx +++ b/src/validation/UserSchema.tsx @@ -3,8 +3,5 @@ import { t } from "@lingui/macro"; export const UserSchema = () => object().shape({ - email: string() - .required(t`Email address is required`) - .email(t`Please enter a valid email address`), fullName: string().required(t`Full name is required`), });