From 21417c65987c002ced7165f10fc448360d6a8e83 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 30 Aug 2022 17:58:17 -0700 Subject: [PATCH] chore: better logic for changing password in ui --- .../views/collections/Edit/Auth/index.tsx | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/admin/components/views/collections/Edit/Auth/index.tsx b/src/admin/components/views/collections/Edit/Auth/index.tsx index d0032d4f09..4dc23c03a4 100644 --- a/src/admin/components/views/collections/Edit/Auth/index.tsx +++ b/src/admin/components/views/collections/Edit/Auth/index.tsx @@ -18,17 +18,11 @@ const baseClass = 'auth-fields'; const Auth: React.FC = (props) => { const { useAPIKey, requirePassword, verify, collection: { slug }, collection, email, operation } = props; const [changingPassword, setChangingPassword] = useState(requirePassword); - const { getField } = useWatchForm(); + const { getField, dispatchFields } = useWatchForm(); const modified = useFormModified(); const enableAPIKey = getField('enableAPIKey'); - useEffect(() => { - if (!modified) { - setChangingPassword(false); - } - }, [modified]); - const { serverURL, routes: { @@ -36,6 +30,15 @@ const Auth: React.FC = (props) => { }, } = useConfig(); + const handleChangePassword = useCallback(async (state: boolean) => { + if (!state) { + dispatchFields({ type: 'REMOVE', path: 'password' }); + dispatchFields({ type: 'REMOVE', path: 'confirm-password' }); + } + + setChangingPassword(state); + }, [dispatchFields]); + const unlock = useCallback(async () => { const url = `${serverURL}${api}/${slug}/unlock`; const response = await fetch(url, { @@ -55,6 +58,12 @@ const Auth: React.FC = (props) => { } }, [serverURL, api, slug, email]); + useEffect(() => { + if (!modified) { + setChangingPassword(false); + } + }, [modified]); + if (collection.auth.disableLocalStrategy) { return null; } @@ -80,7 +89,7 @@ const Auth: React.FC = (props) => { @@ -91,7 +100,7 @@ const Auth: React.FC = (props) => {