Skip to content

Commit

Permalink
Redirect applicants when successfully submitting applications (if pos…
Browse files Browse the repository at this point in the history
…sible) (#136)

* feat: redirect to `/portal` on successful submission

* feat: for non-JS display message from API on success on submit

* fix: use `useRouter` instead of `redirect`
  • Loading branch information
samderanova authored Dec 18, 2023
1 parent 2664368 commit 4b94251
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion apps/api/src/routers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async def apply(
user: Annotated[User, Depends(require_user_identity)],
raw_application_data: Annotated[RawApplicationData, Depends(RawApplicationData)],
resume: Optional[UploadFile] = None,
) -> None:
) -> str:
# check if email is already in database
EXISTING_RECORD = await mongodb_handler.retrieve_one(
Collection.USERS, {"_id": user.uid}
Expand Down Expand Up @@ -137,3 +137,7 @@ async def apply(
# TODO: handle inconsistent results if one service fails

log.info("%s submitted an application", user.uid)
return (
"Thank you for submitting an application to IrvineHacks 2024! Please "
+ "visit https://irvinehacks.com/portal to see your application status."
)
4 changes: 3 additions & 1 deletion apps/site/src/app/apply/sections/Form/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import { FormEvent, useState } from "react";
import { useRouter } from "next/router";
import axios from "axios";

import Button from "@/lib/components/Button/Button";
Expand All @@ -19,6 +20,7 @@ const FIELDS_WITH_OTHER = ["pronouns", "ethnicity", "school", "major"];
export default function Form() {
const [submitting, setSubmitting] = useState(false);
const [sessionExpired, setSessionExpired] = useState(false);
const router = useRouter();

const handleSubmit = async (
event: FormEvent<HTMLFormElement>,
Expand Down Expand Up @@ -46,7 +48,7 @@ export default function Form() {
const res = await axios.post(APPLY_PATH, formData);
if (res.status === 201) {
console.log("Application submitted");
// TODO: show submitted message
router.push("/portal");
}
} catch (err) {
console.error(err);
Expand Down

0 comments on commit 4b94251

Please sign in to comment.