Skip to content

Commit

Permalink
Add success & error message after adding new email to report
Browse files Browse the repository at this point in the history
  • Loading branch information
cipick committed May 15, 2023
1 parent 6949726 commit b4f1ee2
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions client/src/components/CreateEvaluation/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { useCallback } from "react";
import React, { useCallback, useEffect } from "react";
import Button from "@/components/Button";
import { useCreateEvaluationMutation } from "@/redux/api/userApi";
import { object, string, TypeOf } from "zod";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod/dist/zod";
import { toast } from "react-toastify";

const evaluationSchema = object({
email: string()
Expand All @@ -13,7 +14,8 @@ const evaluationSchema = object({
export type EvaluationInput = TypeOf<typeof evaluationSchema>;

const CreateEvaluation = ({ reportId }: { reportId: string }) => {
const [createEvaluation] = useCreateEvaluationMutation();
const [createEvaluation, { isSuccess, isError }] =
useCreateEvaluationMutation();
const { register, handleSubmit, reset } = useForm<EvaluationInput>({
resolver: zodResolver(evaluationSchema),
});
Expand All @@ -24,6 +26,17 @@ const CreateEvaluation = ({ reportId }: { reportId: string }) => {
},
[createEvaluation, reset]
);
useEffect(() => {
if (isSuccess) {
toast.success("Invitația a fost transmisă.");
}
}, [isSuccess]);

useEffect(() => {
if (isError) {
toast.error("Ceva nu a funcționat. Încearcă din nou.");
}
}, [isError]);

return (
<form onSubmit={handleSubmit(onSubmitHandler)}>
Expand Down

1 comment on commit b4f1ee2

@vercel
Copy link

@vercel vercel bot commented on b4f1ee2 May 15, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.