Skip to content

Commit

Permalink
updated minor changes for organzation
Browse files Browse the repository at this point in the history
  • Loading branch information
suxls committed Feb 20, 2025
1 parent 9909b9e commit 45e689b
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions apps/web/src/app/_components/form/review-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,31 @@ export function ReviewForm(props: ReviewFormProps) {
});

const [currentStep, setCurrentStep] = useState<number>(0);
const [validForm, setValidForm] = useState(true);
const [errorMessage, setErrorMessage] = useState<string | null>(null);

const { toast } = useToast();

type FieldName = keyof z.infer<typeof formSchema>;

const profile = api.profile.getCurrentUser.useQuery(undefined, {
refetchOnWindowFocus: false,
});
const profileId = profile.data?.id;

const reviews = api.review.getByProfile.useQuery(
{ id: profileId ?? "" },
{
enabled: !!profileId,
},
);

const canReviewForTerm = (): boolean => {
console.log("reviews", reviews.data);

return false;
};

const next = async (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
e.preventDefault();
const fields = steps[currentStep - 1]?.fields;
Expand All @@ -243,6 +265,11 @@ export function ReviewForm(props: ReviewFormProps) {
return;
}

if (currentStep === 1 && !canReviewForTerm()) {
alert("You have already submitted too many reviews for this term!");
return;
}

// FIXME: Fix the scrolling eslint issue

if (currentStep <= steps.length) {
Expand All @@ -264,33 +291,25 @@ export function ReviewForm(props: ReviewFormProps) {
scroll.scrollToTop({ duration: 250, smooth: true });
};

const [validForm, setValidForm] = useState(true); //wait where do i put these
const { toast } = useToast(); //like at the tipity top?

const [errorMessage, setErrorMessage] = useState<string | null>(null);

const mutation = api.review.create.useMutation({
onError: (error) => {
setValidForm(false);
setErrorMessage(error.message || "An unknown error occurred.");

toast({
title: "Submission Error",
description: (error && error.message) ? error.message : "Something went wrong. Please try again.",
description: error.message || "Something went wrong. Please try again.",
variant: "destructive",
});
},
});




async function onSubmit(values: z.infer<ReviewFormType>) {
try {
await mutation.mutateAsync({
roleId: props.roleId,
profileId: props.profileId,
companyId: props.company?.id ?? "",
companyId: props.company.id,
...values,
});
} catch (error) {
Expand All @@ -302,7 +321,7 @@ export function ReviewForm(props: ReviewFormProps) {
if (validForm) {
return <SubmissionConfirmation />;
} else {
return <SubmissionFailure message={errorMessage || undefined} />;
return <SubmissionFailure message={errorMessage ?? undefined} />;
}
}

Expand Down

0 comments on commit 45e689b

Please sign in to comment.