From 083aa0ea5534de3f4c84746523ba3e90fdad8bf9 Mon Sep 17 00:00:00 2001 From: AndyOoh Date: Sat, 20 Jan 2024 23:41:54 +0700 Subject: [PATCH 1/9] show buttons only in dev --- .../(protected)/components/HomeMain/HomeMain.tsx | 8 +++++--- .../app/(protected)/events/create/form/index.tsx | 15 +++++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/apps/app/src/app/(protected)/components/HomeMain/HomeMain.tsx b/apps/app/src/app/(protected)/components/HomeMain/HomeMain.tsx index cf0869d..9bc93e8 100644 --- a/apps/app/src/app/(protected)/components/HomeMain/HomeMain.tsx +++ b/apps/app/src/app/(protected)/components/HomeMain/HomeMain.tsx @@ -22,9 +22,11 @@ export const HomeMain = () => { - + {process.env.NEXT_PUBLIC_EMULATORS_ON === 'true' && ( + + )} ); }; diff --git a/apps/app/src/app/(protected)/events/create/form/index.tsx b/apps/app/src/app/(protected)/events/create/form/index.tsx index a3e3289..fe1f26d 100644 --- a/apps/app/src/app/(protected)/events/create/form/index.tsx +++ b/apps/app/src/app/(protected)/events/create/form/index.tsx @@ -96,12 +96,15 @@ export const CreateEventForm = () => {
- + {/* {process.env.NODE_ENV === 'development' && ( */} + {process.env.NODE_ENV === 'production' && ( + + )}
From 02de4acfc8c6621001e19cefc0fbb951f475f6e5 Mon Sep 17 00:00:00 2001 From: AndyOoh Date: Sat, 20 Jan 2024 23:42:15 +0700 Subject: [PATCH 2/9] cleanup --- apps/app/src/app/(protected)/events/create/form/index.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/app/src/app/(protected)/events/create/form/index.tsx b/apps/app/src/app/(protected)/events/create/form/index.tsx index fe1f26d..f89f2b5 100644 --- a/apps/app/src/app/(protected)/events/create/form/index.tsx +++ b/apps/app/src/app/(protected)/events/create/form/index.tsx @@ -96,8 +96,7 @@ export const CreateEventForm = () => {
- {/* {process.env.NODE_ENV === 'development' && ( */} - {process.env.NODE_ENV === 'production' && ( + {process.env.NODE_ENV === 'development' && ( - -
- - - ); -}; From 67e7e2f3b6e6ae4c570dd6b392666037956a12df Mon Sep 17 00:00:00 2001 From: AndyOoh Date: Sat, 20 Jan 2024 23:47:05 +0700 Subject: [PATCH 4/9] test button profile page --- .../(protected)/profile/components/form/index.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/app/src/app/(protected)/profile/components/form/index.tsx b/apps/app/src/app/(protected)/profile/components/form/index.tsx index 2791b43..6c7e774 100644 --- a/apps/app/src/app/(protected)/profile/components/form/index.tsx +++ b/apps/app/src/app/(protected)/profile/components/form/index.tsx @@ -74,12 +74,14 @@ export const EditProfileForm = () => {
- + {process.env.NODE_ENV === 'development' && ( + + )}
From 52639c3e6bd5ed20633b82f0bde13c39beb77532 Mon Sep 17 00:00:00 2001 From: AndyOoh Date: Sat, 20 Jan 2024 23:49:03 +0700 Subject: [PATCH 5/9] test button settings page --- .../settings/components/delete-acc-form/index.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/app/src/app/(protected)/settings/components/delete-acc-form/index.tsx b/apps/app/src/app/(protected)/settings/components/delete-acc-form/index.tsx index ba5ce39..bc2930e 100644 --- a/apps/app/src/app/(protected)/settings/components/delete-acc-form/index.tsx +++ b/apps/app/src/app/(protected)/settings/components/delete-acc-form/index.tsx @@ -98,12 +98,13 @@ export const DeleteAccountForm = () => { /> -
-
- -
+ {process.env.NODE_ENV === 'development' && ( +
+ +
+ )} {/* */} From 19b41a05a455782a6364b3fb9af58a7656c5765b Mon Sep 17 00:00:00 2001 From: AndyOoh Date: Sat, 20 Jan 2024 23:50:30 +0700 Subject: [PATCH 6/9] remove /test --- apps/app/src/app/test/page.tsx | 118 --------------------------------- 1 file changed, 118 deletions(-) delete mode 100644 apps/app/src/app/test/page.tsx diff --git a/apps/app/src/app/test/page.tsx b/apps/app/src/app/test/page.tsx deleted file mode 100644 index 5429d64..0000000 --- a/apps/app/src/app/test/page.tsx +++ /dev/null @@ -1,118 +0,0 @@ -'use client'; - -import { auth, getCloudFunction } from '__firebase/clientApp'; -import React, { MouseEvent, useEffect, useState } from 'react'; -import { useAuthState, useSignInWithGoogle, useUpdateProfile } from 'react-firebase-hooks/auth'; -import { useRouter } from 'next/navigation'; - -function Test() { - const [signInWithGoogle, _userG, loadingGoogle, errorGoogle] = useSignInWithGoogle(auth); - const [user, loading, error] = useAuthState(auth); - const [_loading, _setLoading] = useState(true); - const router = useRouter(); - - // auth.onAuthStateChanged(async user => { - // console.log('onAuthStateChanged called!!!!!!!!!'); - // // _setLoading(true); - // if (user) { - // const token = await user.getIdTokenResult(true); - // console.log('🤣 onAuthStateChanged:', token); - // if (token.claims.basic_info_done) { - // router.push('/test-success'); - // } - // } else { - // console.log('🤣 onAuthStateChanged: user is null'); - // } - // // _setLoading(false); - // }); - - useEffect(() => { - console.log('useEffect called!!!!!!!!!'); - _setLoading(true); - const fetchToken = async () => { - const token = await user?.getIdTokenResult(); - console.log('🚀 file: page.tsx:11 user:', user); - console.log('🚀 file: PublicRoutes.tsx:19 token:', token); - token?.claims?.basic_info_done ? router.push('/test-success') : _setLoading(false); - }; - - fetchToken(); - }, [user, router]); - - // useEffect(() => { - // console.log('useEffect called!!!!!!!!!'); - // }, []); - - // useEffect(() => { - // console.log('useEffect called 222222222222'); - // }, [user]); - - const onClick = async (e: MouseEvent) => { - try { - e.preventDefault(); - const succes = await signInWithGoogle(); - } catch (error) { - console.log('🚀 file: page.tsx:13 error:', error); - } - }; - - const onClick2 = async (e: MouseEvent) => { - try { - e.preventDefault(); - - const setCustomClaims = getCloudFunction('setCustomClaims'); // Our custom function - const resSetCC = await setCustomClaims({ - uid: user?.uid, - payload: { basic_info_done: true }, - }); - console.log('🚀 file: page.tsx:55 resSetCC:', resSetCC); - const token = await user.getIdTokenResult(true); - if (token.claims.basic_info_done) { - // router.push('/test-success'); - router.push('/'); - } else { - console.log('🚀 claims.basic_info_done fdlse:', token); - } - - // const lala = user.getIdToken(true); - // user. - } catch (error) { - console.log('🚀 file: page.tsx:13 error:', error); - } - }; - const onClick3 = async (e: MouseEvent) => { - try { - e.preventDefault(); - const token = await user.getIdTokenResult(true); - console.log('🚀 file: page.tsx:75 token:', token); - } catch (error) { - console.log('🚀 file: page.tsx:77 error:', error); - } - }; - - return loading || _loading ? ( -
loading...
- ) : ( -
-

Testing Oauth and auth object

- {user &&

user displayName: {user?.displayName}

} -
- -
-
- -
-
- -
-
- ); -} - -export default Test; From e31136e9ecf50bebc2e8304f80710cb888f5009e Mon Sep 17 00:00:00 2001 From: AndyOoh Date: Sat, 20 Jan 2024 23:54:06 +0700 Subject: [PATCH 7/9] refactor, cleanup --- .../components/delete-acc-form/index.tsx | 38 ++++++------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/apps/app/src/app/(protected)/settings/components/delete-acc-form/index.tsx b/apps/app/src/app/(protected)/settings/components/delete-acc-form/index.tsx index bc2930e..f62ffc0 100644 --- a/apps/app/src/app/(protected)/settings/components/delete-acc-form/index.tsx +++ b/apps/app/src/app/(protected)/settings/components/delete-acc-form/index.tsx @@ -10,7 +10,7 @@ import { TextInput, FormError, ActionButton } from 'ui'; import { useAuthState, useDeleteUser } from 'react-firebase-hooks/auth'; import { reAuthenticate } from '__firebase/utilities'; import { useRouter } from 'next/navigation'; -import { DevTool } from '@hookform/devtools'; +import { onTestForm } from '__utils/helpers'; export const DeleteAccountForm = () => { const { currentUser } = useContext(CurrUserContext); @@ -19,19 +19,12 @@ export const DeleteAccountForm = () => { const [deleteUser, loading_delete, error_delete] = useDeleteUser(auth); const router = useRouter(); - const { - register, - reset, - handleSubmit, - setError, - control, - watch, - - formState: { errors, isDirty, isValid, isSubmitting, isSubmitSuccessful, dirtyFields }, - } = useForm({ - mode: 'onTouched', - resolver: providerId === 'password' ? yupResolver(deleteUserSchema) : null, - }); + const { register, reset, handleSubmit, setError, watch, formState, getValues } = + useForm({ + mode: 'onTouched', + resolver: providerId === 'password' ? yupResolver(deleteUserSchema) : null, + }); + const { errors, isDirty, isValid, isSubmitting, isSubmitSuccessful, dirtyFields } = formState; useEffect(() => { if (isSubmitSuccessful) { @@ -58,16 +51,6 @@ export const DeleteAccountForm = () => { const buttonDisabled = providerId === 'password' ? !isDirty || !isValid : false; - const onTest = () => { - const data = watch(); - // const changedData = getChangedFormData(data, dirtyFields); - console.log('🚀 file: index.tsx:66 data:', data); - console.log('🚀 file: index.tsx:66 dirtyFields:', dirtyFields); - // console.log('🚀 file: index.tsx:66 filteredData:', changedData); - console.log('🚀 file: index.tsx:66 isValid:', isValid); - console.log('🚀 file: index.tsx:66 errors:', errors); - }; - return currentUser ? (

Delete Account

@@ -75,7 +58,6 @@ export const DeleteAccountForm = () => {

Deleting your account will remove all of your information from our database.

This cannot be undone.

- {/*
*/}
{providerId === 'password' && (
@@ -100,14 +82,16 @@ export const DeleteAccountForm = () => {
{process.env.NODE_ENV === 'development' && (
-
)}
- {/* */}
) : null; }; From 196f08311fe223e9694f73f88b056f1eadad790e Mon Sep 17 00:00:00 2001 From: AndyOoh Date: Sat, 20 Jan 2024 23:55:09 +0700 Subject: [PATCH 8/9] cleanup --- .../settings/components/delete-acc-form/index.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/apps/app/src/app/(protected)/settings/components/delete-acc-form/index.tsx b/apps/app/src/app/(protected)/settings/components/delete-acc-form/index.tsx index f62ffc0..98c61a6 100644 --- a/apps/app/src/app/(protected)/settings/components/delete-acc-form/index.tsx +++ b/apps/app/src/app/(protected)/settings/components/delete-acc-form/index.tsx @@ -24,7 +24,7 @@ export const DeleteAccountForm = () => { mode: 'onTouched', resolver: providerId === 'password' ? yupResolver(deleteUserSchema) : null, }); - const { errors, isDirty, isValid, isSubmitting, isSubmitSuccessful, dirtyFields } = formState; + const { errors, isDirty, isValid, isSubmitting, isSubmitSuccessful } = formState; useEffect(() => { if (isSubmitSuccessful) { @@ -36,13 +36,10 @@ export const DeleteAccountForm = () => { try { const result = providerId === 'password' ? await reAuthenticate(data.password) : await reAuthenticate(); - result instanceof Error ? setError('password', { message: 'Incorrect password' }) : await deleteUser(); - router.push('/'); - return; } catch (error) { console.log('🚀 file: WorkInfo.tsx:59 error:', error); From 4c428378c4789d2be7f5c0d84719d738b2de435e Mon Sep 17 00:00:00 2001 From: AndyOoh Date: Sat, 20 Jan 2024 23:55:58 +0700 Subject: [PATCH 9/9] delete /test-success --- apps/app/src/app/test-success/page.tsx | 47 -------------------------- 1 file changed, 47 deletions(-) delete mode 100644 apps/app/src/app/test-success/page.tsx diff --git a/apps/app/src/app/test-success/page.tsx b/apps/app/src/app/test-success/page.tsx deleted file mode 100644 index c2ac82e..0000000 --- a/apps/app/src/app/test-success/page.tsx +++ /dev/null @@ -1,47 +0,0 @@ -'use client'; - -import { auth } from '__firebase/clientApp'; -import { useRouter } from 'next/navigation'; -import React, { use, useEffect, useState } from 'react'; -import { useAuthState } from 'react-firebase-hooks/auth'; - -type Props = {}; - -function TestSuccess({}: Props) { - const [user, loading, error] = useAuthState(auth); - // const [_loading, _setLoading] = useState(true); - const router = useRouter(); - - useEffect(() => { - // _setLoading(true); - const fetchToken = async () => { - const token = await user?.getIdTokenResult(); - console.log('🚀 file: PublicRoutes.tsx:19 token:', token); - // !loading && !token?.claims.basic_info_done ? router.push('/test') : _setLoading(false); - !loading && !token?.claims.basic_info_done && router.push('/test'); - }; - - fetchToken(); - }, [user, router, loading]); - - const onLogout = async () => { - try { - await auth.signOut(); - } catch (error) { - console.log('🚀 file: page.tsx:13 error:', error); - } - }; - - return loading ? ( -
Loading...
- ) : ( -
- SUccessfully user - -
- ); -} - -export default TestSuccess;