Skip to content

Commit

Permalink
Merge pull request #65 from AndyOooh/ED1-48-fix-form-Test-buttons
Browse files Browse the repository at this point in the history
Ed1 48 fix form test buttons
  • Loading branch information
AndyOooh authored Jan 20, 2024
2 parents 376a4d4 + 4c42837 commit 6099612
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 337 deletions.
8 changes: 5 additions & 3 deletions apps/app/src/app/(protected)/components/HomeMain/HomeMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ export const HomeMain = () => {
<Stats />
<ReferralAd />

<button className='btn' onClick={submitHandler}>
Test Emulator
</button>
{process.env.NEXT_PUBLIC_EMULATORS_ON === 'true' && (
<button className='btn' onClick={submitHandler}>
Test Emulator
</button>
)}
</div>
);
};
14 changes: 8 additions & 6 deletions apps/app/src/app/(protected)/events/create/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,14 @@ export const CreateEventForm = () => {

<div className='w-full sticky bottom-0 p-4'>
<ActionButton text='Update' disabled={!isDirty || !isValid} loading={isSubmitting} />
<button
type='button'
onClick={() => onTestForm(formState, getValues())}
className='btn btn-neutral'>
Test
</button>
{process.env.NODE_ENV === 'development' && (
<button
type='button'
onClick={() => onTestForm(formState, getValues())}
className='btn btn-neutral'>
Test
</button>
)}
</div>
</form>
<DevTool control={control} />
Expand Down
122 changes: 0 additions & 122 deletions apps/app/src/app/(protected)/events/create/form/test-field-array.tsx

This file was deleted.

14 changes: 8 additions & 6 deletions apps/app/src/app/(protected)/profile/components/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ export const EditProfileForm = () => {

<div className='w-full sticky bottom-0 p-4'>
<ActionButton text='Update' disabled={!isDirty || !isValid} loading={isSubmitting} />
<button
type='button'
onClick={() => onTestForm(formState, getValues())}
className='btn btn-neutral'>
Test
</button>
{process.env.NODE_ENV === 'development' && (
<button
type='button'
onClick={() => onTestForm(formState, getValues())}
className='btn btn-neutral'>
Test
</button>
)}
</div>
</form>
<DevTool control={control} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<IdeleteUserSchema>({
mode: 'onTouched',
resolver: providerId === 'password' ? yupResolver(deleteUserSchema) : null,
});
const { register, reset, handleSubmit, setError, watch, formState, getValues } =
useForm<IdeleteUserSchema>({
mode: 'onTouched',
resolver: providerId === 'password' ? yupResolver(deleteUserSchema) : null,
});
const { errors, isDirty, isValid, isSubmitting, isSubmitSuccessful } = formState;

useEffect(() => {
if (isSubmitSuccessful) {
Expand All @@ -43,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);
Expand All @@ -58,24 +48,13 @@ 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 ? (
<div className='flex flex-col gap-2 mt-4'>
<h2 className='text-xl'>Delete Account</h2>
<div className='card bg-base-100'>
<form onSubmit={handleSubmit(onSubmit)} noValidate className='card-body'>
<p>Deleting your account will remove all of your information from our database.</p>
<p className='font-bold text-error'>This cannot be undone.</p>
{/* <div className='w-full grid grid-cols-2 gap-6 align-middle justify-center'> */}
<div className='w-full flex flex-col gap-6 items-center'>
{providerId === 'password' && (
<div className='w-fit'>
Expand All @@ -98,15 +77,18 @@ export const DeleteAccountForm = () => {
/>
</div>
</div>
<div></div>
<div className='w-full sticky bottom-0 p-4'>
<button type='button' onClick={onTest} className='btn btn-neutral'>
Test
</button>
</div>
{process.env.NODE_ENV === 'development' && (
<div className='w-full sticky bottom-0 p-4'>
<button
type='button'
onClick={() => onTestForm(formState, getValues())}
className='btn btn-neutral'>
Test
</button>
</div>
)}
</form>
</div>
{/* <DevTool control={control} /> */}
</div>
) : null;
};
47 changes: 0 additions & 47 deletions apps/app/src/app/test-success/page.tsx

This file was deleted.

Loading

1 comment on commit 6099612

@vercel
Copy link

@vercel vercel bot commented on 6099612 Jan 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

dev-event-dee2 – ./apps/app

dev-event-dee2-andyoooh.vercel.app
dev-event-dee2.vercel.app
dev-event-dee2-git-main-andyoooh.vercel.app

Please sign in to comment.