Skip to content

Commit

Permalink
fix clearing password fields on React auth forms (#395)
Browse files Browse the repository at this point in the history
* fix clearing password fields on post

* fix formatting
  • Loading branch information
daleweaver777 authored Jul 17, 2024
1 parent 8a60327 commit 1446994
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, FormEventHandler } from 'react';
import { FormEventHandler } from 'react';
import GuestLayout from '@/Layouts/GuestLayout';
import InputError from '@/Components/InputError';
import InputLabel from '@/Components/InputLabel';
Expand All @@ -11,16 +11,12 @@ export default function ConfirmPassword() {
password: '',
});

useEffect(() => {
return () => {
reset('password');
};
}, []);

const submit: FormEventHandler = (e) => {
e.preventDefault();

post(route('password.confirm'));
post(route('password.confirm'), {
onFinish: () => reset('password'),
});
};

return (
Expand Down
12 changes: 4 additions & 8 deletions stubs/inertia-react-ts/resources/js/Pages/Auth/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, FormEventHandler } from 'react';
import { FormEventHandler } from 'react';
import Checkbox from '@/Components/Checkbox';
import GuestLayout from '@/Layouts/GuestLayout';
import InputError from '@/Components/InputError';
Expand All @@ -14,16 +14,12 @@ export default function Login({ status, canResetPassword }: { status?: string, c
remember: false,
});

useEffect(() => {
return () => {
reset('password');
};
}, []);

const submit: FormEventHandler = (e) => {
e.preventDefault();

post(route('login'));
post(route('login'), {
onFinish: () => reset('password'),
});
};

return (
Expand Down
12 changes: 4 additions & 8 deletions stubs/inertia-react-ts/resources/js/Pages/Auth/Register.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, FormEventHandler } from 'react';
import { FormEventHandler } from 'react';
import GuestLayout from '@/Layouts/GuestLayout';
import InputError from '@/Components/InputError';
import InputLabel from '@/Components/InputLabel';
Expand All @@ -14,16 +14,12 @@ export default function Register() {
password_confirmation: '',
});

useEffect(() => {
return () => {
reset('password', 'password_confirmation');
};
}, []);

const submit: FormEventHandler = (e) => {
e.preventDefault();

post(route('register'));
post(route('register'), {
onFinish: () => reset('password', 'password_confirmation'),
});
};

return (
Expand Down
12 changes: 4 additions & 8 deletions stubs/inertia-react-ts/resources/js/Pages/Auth/ResetPassword.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, FormEventHandler } from 'react';
import { FormEventHandler } from 'react';
import GuestLayout from '@/Layouts/GuestLayout';
import InputError from '@/Components/InputError';
import InputLabel from '@/Components/InputLabel';
Expand All @@ -14,16 +14,12 @@ export default function ResetPassword({ token, email }: { token: string, email:
password_confirmation: '',
});

useEffect(() => {
return () => {
reset('password', 'password_confirmation');
};
}, []);

const submit: FormEventHandler = (e) => {
e.preventDefault();

post(route('password.store'));
post(route('password.store'), {
onFinish: () => reset('password', 'password_confirmation'),
});
};

return (
Expand Down
11 changes: 3 additions & 8 deletions stubs/inertia-react/resources/js/Pages/Auth/ConfirmPassword.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useEffect } from 'react';
import GuestLayout from '@/Layouts/GuestLayout';
import InputError from '@/Components/InputError';
import InputLabel from '@/Components/InputLabel';
Expand All @@ -11,16 +10,12 @@ export default function ConfirmPassword() {
password: '',
});

useEffect(() => {
return () => {
reset('password');
};
}, []);

const submit = (e) => {
e.preventDefault();

post(route('password.confirm'));
post(route('password.confirm'), {
onFinish: () => reset('password'),
});
};

return (
Expand Down
11 changes: 3 additions & 8 deletions stubs/inertia-react/resources/js/Pages/Auth/Login.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useEffect } from 'react';
import Checkbox from '@/Components/Checkbox';
import GuestLayout from '@/Layouts/GuestLayout';
import InputError from '@/Components/InputError';
Expand All @@ -14,16 +13,12 @@ export default function Login({ status, canResetPassword }) {
remember: false,
});

useEffect(() => {
return () => {
reset('password');
};
}, []);

const submit = (e) => {
e.preventDefault();

post(route('login'));
post(route('login'), {
onFinish: () => reset('password'),
});
};

return (
Expand Down
11 changes: 3 additions & 8 deletions stubs/inertia-react/resources/js/Pages/Auth/Register.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useEffect } from 'react';
import GuestLayout from '@/Layouts/GuestLayout';
import InputError from '@/Components/InputError';
import InputLabel from '@/Components/InputLabel';
Expand All @@ -14,16 +13,12 @@ export default function Register() {
password_confirmation: '',
});

useEffect(() => {
return () => {
reset('password', 'password_confirmation');
};
}, []);

const submit = (e) => {
e.preventDefault();

post(route('register'));
post(route('register'), {
onFinish: () => reset('password', 'password_confirmation'),
});
};

return (
Expand Down
11 changes: 3 additions & 8 deletions stubs/inertia-react/resources/js/Pages/Auth/ResetPassword.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useEffect } from 'react';
import GuestLayout from '@/Layouts/GuestLayout';
import InputError from '@/Components/InputError';
import InputLabel from '@/Components/InputLabel';
Expand All @@ -14,16 +13,12 @@ export default function ResetPassword({ token, email }) {
password_confirmation: '',
});

useEffect(() => {
return () => {
reset('password', 'password_confirmation');
};
}, []);

const submit = (e) => {
e.preventDefault();

post(route('password.store'));
post(route('password.store'), {
onFinish: () => reset('password', 'password_confirmation'),
});
};

return (
Expand Down

0 comments on commit 1446994

Please sign in to comment.