diff --git a/api/src/rpc/router.ts b/api/src/rpc/router.ts index 22cbf0bc..ae1d2803 100644 --- a/api/src/rpc/router.ts +++ b/api/src/rpc/router.ts @@ -470,7 +470,6 @@ export function createRouter(params: { currentUser: user }) ), - "getAllowedEmailRegexp": loggedProcedure.query(() => coreContext.userApi.getAllowedEmailRegexp()), "getAllOrganizations": loggedProcedure.query(() => dbApi.agent.getAllOrganizations()), "updateEmail": loggedProcedure .input( diff --git a/web/src/core/adapter/sillApi.ts b/web/src/core/adapter/sillApi.ts index 5312de41..f6aeb20c 100644 --- a/web/src/core/adapter/sillApi.ts +++ b/web/src/core/adapter/sillApi.ts @@ -135,9 +135,6 @@ export function createSillApi(params: { return out; }, - "getAllowedEmailRegexp": memoize(() => trpcClient.getAllowedEmailRegexp.query(), { - "promise": true - }), "getAllOrganizations": memoize(() => trpcClient.getAllOrganizations.query(), { "promise": true }), diff --git a/web/src/core/adapter/sillApiMock.ts b/web/src/core/adapter/sillApiMock.ts index 77549613..3faaedea 100644 --- a/web/src/core/adapter/sillApiMock.ts +++ b/web/src/core/adapter/sillApiMock.ts @@ -211,7 +211,6 @@ export const sillApi: SillApi = { "updateEmail": async ({ newEmail }) => { console.log(`Update email ${newEmail}`); }, - "getAllowedEmailRegexp": memoize(async () => "/gouv.fr$/", { "promise": true }), "getAllOrganizations": memoize(async () => ["DINUM", "CNRS", "ESR"], { "promise": true }), diff --git a/web/src/core/ports/SillApi.ts b/web/src/core/ports/SillApi.ts index 2c7ba052..b3b55b3e 100644 --- a/web/src/core/ports/SillApi.ts +++ b/web/src/core/ports/SillApi.ts @@ -73,10 +73,6 @@ export type SillApi = { params: TrpcRouterInput["updateEmail"] ) => Promise; - getAllowedEmailRegexp: { - (): Promise; - clear: () => void; - }; getAllOrganizations: { (params: TrpcRouterInput["getAllOrganizations"]): Promise< TrpcRouterOutput["getAllOrganizations"] diff --git a/web/src/core/usecases/userAccountManagement/state.ts b/web/src/core/usecases/userAccountManagement/state.ts index c3fa7508..0e4a5da7 100644 --- a/web/src/core/usecases/userAccountManagement/state.ts +++ b/web/src/core/usecases/userAccountManagement/state.ts @@ -15,7 +15,6 @@ namespace State { export type Ready = { stateDescription: "ready"; accountManagementUrl: string | undefined; - allowedEmailRegexpStr: string; allOrganizations: string[]; organization: { value: string | null; @@ -63,7 +62,6 @@ export const { reducer, actions } = createUsecaseActions({ }: { payload: { accountManagementUrl: string | undefined; - allowedEmailRegexpStr: string; organization: string | null; email: string; allOrganizations: string[]; @@ -74,7 +72,6 @@ export const { reducer, actions } = createUsecaseActions({ ) => { const { accountManagementUrl, - allowedEmailRegexpStr, organization, email, allOrganizations, @@ -85,7 +82,6 @@ export const { reducer, actions } = createUsecaseActions({ return { "stateDescription": "ready", accountManagementUrl, - allowedEmailRegexpStr, allOrganizations, "organization": { "value": organization, diff --git a/web/src/core/usecases/userAccountManagement/thunks.ts b/web/src/core/usecases/userAccountManagement/thunks.ts index 89059e89..74d7c2ca 100644 --- a/web/src/core/usecases/userAccountManagement/thunks.ts +++ b/web/src/core/usecases/userAccountManagement/thunks.ts @@ -23,14 +23,8 @@ export const thunks = { const user = await getUser(); - const [ - { keycloakParams }, - allowedEmailRegexpStr, - allOrganizations, - { agent } - ] = await Promise.all([ + const [{ keycloakParams }, allOrganizations, { agent }] = await Promise.all([ sillApi.getOidcParams(), - sillApi.getAllowedEmailRegexp(), sillApi.getAllOrganizations(), sillApi.getAgent({ "email": user.email }) ]); @@ -39,7 +33,6 @@ export const thunks = { dispatch( actions.initialized({ - allowedEmailRegexpStr, "email": user.email, "organization": organization, "accountManagementUrl": diff --git a/web/src/ui/pages/account/Account.tsx b/web/src/ui/pages/account/Account.tsx index 242b8c12..b4801fa6 100644 --- a/web/src/ui/pages/account/Account.tsx +++ b/web/src/ui/pages/account/Account.tsx @@ -7,7 +7,6 @@ import { Equals } from "tsafe"; import { declareComponentKeys } from "i18nifty"; import { useCore, useCoreState } from "core"; import { Input } from "@codegouvfr/react-dsfr/Input"; -import { z } from "zod"; import { Button } from "@codegouvfr/react-dsfr/Button"; import { OrganizationField } from "../../shared/PromptForOrganization"; import type { PageRoute } from "./route"; @@ -55,40 +54,19 @@ function AccountReady(props: { className?: string }) { const { t } = useTranslation({ Account }); - const { - email, - organization, - aboutAndIsPublic, - doSupportAccountManagement, - allowedEmailRegExp - } = (function useClosure() { - const state = useCoreState("userAccountManagement", "main"); + const { email, aboutAndIsPublic, doSupportAccountManagement } = + (function useClosure() { + const state = useCoreState("userAccountManagement", "main"); - assert(state !== undefined); + assert(state !== undefined); - const { allowedEmailRegexpStr, ...rest } = state; - - const allowedEmailRegExp = useMemo( - () => new RegExp(allowedEmailRegexpStr), - [allowedEmailRegexpStr] - ); - - return { - ...rest, - allowedEmailRegExp - }; - })(); + return state; + })(); const { isDark } = useIsDark(); const { userAccountManagement } = useCore().functions; - const [emailInputValue, setEmailInputValue] = useState(email.value); - - const [organizationInputValue, setOrganizationInputValue] = useState( - organization.value ?? null - ); - const evtAboutInputValue = useConst(() => Evt.create(aboutAndIsPublic.about)); /* prettier-ignore */ @@ -116,22 +94,6 @@ function AccountReady(props: { className?: string }) { evtAboutInputValue.state = text; }, []); - const emailInputValueErrorMessage = (() => { - try { - z.string().email().parse(emailInputValue); - } catch { - return t("not a valid email"); - } - - if (!allowedEmailRegExp.test(emailInputValue)) { - return t("email domain not allowed", { - "domain": emailInputValue.split("@")[1] - }); - } - - return undefined; - })(); - const { classes, cx, css } = useStyles(); return ( @@ -142,21 +104,11 @@ function AccountReady(props: { className?: string }) { setEmailInputValue(event.target.value), - "value": emailInputValue, + "value": email.value, "name": "email", "type": "email", - "id": "email", - "onKeyDown": event => { - if (event.key === "Escape") { - setEmailInputValue(email.value); - } - } + "id": "email" }} - state={ - emailInputValueErrorMessage === undefined ? undefined : "error" - } - stateRelatedMessage={emailInputValueErrorMessage} disabled={true} />