fix: use review-schema and rtk loading-state
This commit is contained in:
parent
e50187dea1
commit
b405fc315b
@ -4,16 +4,12 @@ import { z } from 'zod';
|
||||
import { requestTaylor } from '@/app/api-utlities/clients/taylor.client';
|
||||
import { createReviewMutation } from '@/app/api-utlities/requests/common';
|
||||
|
||||
import { reviewSchema } from '@/features/review-form/model/review-form.schema';
|
||||
|
||||
export const POST = async (req: NextRequest) => {
|
||||
const body = await req.json();
|
||||
|
||||
const validatedRequest = z
|
||||
.object({
|
||||
name: z.string(),
|
||||
text: z.string(),
|
||||
rating: z.number().min(0).max(5),
|
||||
})
|
||||
.parse(body);
|
||||
const validatedRequest = reviewSchema.parse(body);
|
||||
|
||||
await requestTaylor(
|
||||
{ mutation: createReviewMutation },
|
||||
|
||||
@ -33,10 +33,9 @@ import { ReviewFormValues, reviewSchema } from '../model/review-form.schema';
|
||||
|
||||
export function ReviewForm() {
|
||||
const [openReviewFormDialog, setOpenReviewFormDialog] = useState(false);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [hoveredStar, setHoveredStar] = useState(0);
|
||||
|
||||
const [createReview] = useCreateReviewMutation();
|
||||
const [createReview, { isLoading: isSubmitting }] = useCreateReviewMutation();
|
||||
|
||||
const form = useForm<ReviewFormValues>({
|
||||
resolver: zodResolver(reviewSchema),
|
||||
@ -48,8 +47,6 @@ export function ReviewForm() {
|
||||
});
|
||||
|
||||
const onSubmit = async (data: ReviewFormValues) => {
|
||||
setIsSubmitting(true);
|
||||
|
||||
try {
|
||||
await createReview(data);
|
||||
|
||||
@ -69,8 +66,6 @@ export function ReviewForm() {
|
||||
duration: 5000,
|
||||
},
|
||||
);
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user