Skip to content

Commit

Permalink
feat: request reimbursement loading state
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhu021 committed May 27, 2024
1 parent 12084b6 commit 55b5802
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/app/request-reimbursement/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const formSchema = z.object({

export default function Page() {
const { isLoaded, isSignedIn, user } = useUser();
const [loading, setLoading] = useState(false);
const [submitDisabled, setSubmitDisabled] = useState(false);

const router = useRouter();
Expand All @@ -61,6 +62,7 @@ export default function Page() {
// submisson handler
function onSubmit(values: z.infer<typeof formSchema>) {
setSubmitDisabled(true);
setLoading(true);
// initialize multipart form data
const formData = new FormData();
// append all form values to form data
Expand All @@ -78,6 +80,7 @@ export default function Page() {
return response.json();
}
setSubmitDisabled(false);
setLoading(false);
throw new Error("Failed to submit reimbursement");
})
.then(() => {
Expand All @@ -95,11 +98,12 @@ export default function Page() {
})
.catch((error) => {
setSubmitDisabled(false);
setLoading(false);
console.error(error);
});
}

if (!isLoaded) {
if (!isLoaded || loading) {
return <FullscreenSpinner />;
}
if (!isSignedIn) {
Expand Down

0 comments on commit 55b5802

Please sign in to comment.