From 6eb390e60c2a44bf3e51cb52883f670a36928f49 Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Mon, 8 Dec 2025 12:11:09 +0330 Subject: [PATCH] submit review --- .../(Main)/order/rate/[orderId]/page.tsx | 146 +++++++++++++++--- src/app/[name]/(Main)/order/rate/enum/Enum.ts | 15 ++ .../(Main)/order/rate/hooks/useRateData.ts | 8 + .../(Main)/order/rate/service/RateService.ts | 7 + .../[name]/(Main)/order/rate/types/Types.ts | 8 + src/app/globals.css | 24 +-- src/components/utils/RateSelectionBar.tsx | 7 +- src/locales/fa/rating.json | 66 ++++---- 8 files changed, 213 insertions(+), 68 deletions(-) create mode 100644 src/app/[name]/(Main)/order/rate/enum/Enum.ts create mode 100644 src/app/[name]/(Main)/order/rate/hooks/useRateData.ts create mode 100644 src/app/[name]/(Main)/order/rate/service/RateService.ts create mode 100644 src/app/[name]/(Main)/order/rate/types/Types.ts diff --git a/src/app/[name]/(Main)/order/rate/[orderId]/page.tsx b/src/app/[name]/(Main)/order/rate/[orderId]/page.tsx index f2afa22..dccabe9 100644 --- a/src/app/[name]/(Main)/order/rate/[orderId]/page.tsx +++ b/src/app/[name]/(Main)/order/rate/[orderId]/page.tsx @@ -6,9 +6,14 @@ import { TabHeader } from '@/components/tab/TabHeader'; import { Button } from '@/components/ui/button'; import RateSelectionBar from '@/components/utils/RateSelectionBar'; import clsx from 'clsx'; -import { useParams } from 'next/navigation'; -import React from 'react' +import { useParams, useRouter } from 'next/navigation'; +import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; +import { useCreateRate } from '../hooks/useRateData'; +import { CreateRateType } from '../types/Types'; +import { toast } from '@/components/Toast'; +import { PositivePointEnum, NegativePointEnum } from '../enum/Enum'; +import { extractErrorMessage } from '@/lib/func'; type Props = object @@ -17,24 +22,61 @@ type Params = { } function RatingOrderIndex({ }: Props) { - const params: Params = useParams(); - console.log(params); + const { t } = useTranslation("rating"); + const params: Params = useParams(); + const router = useRouter(); + const urlParams = new URLSearchParams(window.location.search); + const { mutate: createRate, isPending } = useCreateRate(); + + const [rating, setRating] = useState(5); + const [comment, setComment] = useState(''); + const [positivePoints, setPositivePoints] = useState([]); + const [negativePoints, setNegativePoints] = useState([]); + + const positivePointsArray = [ + PositivePointEnum.GREAT_TASTE, + PositivePointEnum.FAST_DELIVERY, + PositivePointEnum.GOOD_QUALITY, + PositivePointEnum.GOOD_PORTION_SIZE, + PositivePointEnum.FRIENDLY_SERVICE, + ]; + + const negativePointsArray = [ + NegativePointEnum.SMALL_PORTION, + NegativePointEnum.SLOW_DELIVERY, + NegativePointEnum.POOR_QUALITY, + NegativePointEnum.OVERPRICED, + NegativePointEnum.UNFRIENDLY_SERVICE, + ]; + + const handleToggle = (pointValue: string, isPositive: boolean) => (checked: boolean) => { + const setter = isPositive ? setPositivePoints : setNegativePoints; + + if (checked) { + setter(prev => [...prev, pointValue]); + } else { + setter(prev => prev.filter(p => p !== pointValue)); + } + }; const badPoitns = () => { return ( <>
- {[...Array(6)].map((_, i) => ( + {negativePointsArray.map((point) => ( - {t(`Tabs.Weeknesses.Options.${i}`)} + key={point} + name={`weekness_${point}`} + // @ts-expect-error - Type mismatch between custom ToggleButton and React types + onToggle={handleToggle(point, false)} + > + {t(`Tabs.Weeknesses.Options.${point}`)} ))}
@@ -46,9 +88,14 @@ function RatingOrderIndex({ }: Props) { return ( <>
- {[...Array(6)].map((_, i) => ( - - {t(`Tabs.Strengths.Options.${i}`)} + {positivePointsArray.map((point) => ( + + {t(`Tabs.Strengths.Options.${point}`)} ))}
@@ -56,11 +103,41 @@ function RatingOrderIndex({ }: Props) { ) } + const handleRatingChange = (value: number[]) => { + setRating(value[0]); + }; + + const handleCancel = () => { + router.back(); + }; + const submitForm = (e: React.FormEvent) => { e.preventDefault(); - const formData = new FormData(e.currentTarget); - console.log(formData.get('rating')) - } + + if (rating === 0) { + toast(t("Errors.RatingRequired") || "لطفا امتیاز خود را انتخاب کنید", "error"); + return; + } + + const rateData: CreateRateType = { + foodId: urlParams.get('foodId') || '', + orderId: params.orderId, + rating, + comment, + positivePoints, + negativePoints, + }; + + createRate(rateData, { + onSuccess: () => { + toast(t("Success") || "نظر شما با موفقیت ثبت شد", "success"); + router.back(); + }, + onError: (error) => { + toast(extractErrorMessage(error), "error"); + }, + }); + }; return (
@@ -70,7 +147,11 @@ function RatingOrderIndex({ }: Props) {
- +
@@ -81,33 +162,48 @@ function RatingOrderIndex({ }: Props) { ...TabContainerClassNames, wrapper: 'p-2!', scrollView: clsx( - 'border-none! rounded-xl! gap-0! h-full bg-[#EAECF0]! dark:bg-neutral-900! not-dark:gradient-border! grid! grid-cols-2 px-2! py-2! !pb-2 w-full overflow-y-hidden justify-center items-center', + 'border-none! rounded-xl! gap-0! h-full bg-[#EAECF0]! dark:bg-neutral-900! not-dark:gradient-border! grid! grid-cols-2 px-2! py-2! pb-2! w-full overflow-y-hidden justify-center items-center', ), title: 'text-sm2! font-normal mt-1', header: 'rounded-lg h-7! w-full', - headerActive: 'bg-primary', - titleActive: 'text-accent' + headerActive: 'bg-white', + titleActive: 'text-black' }}>
- +
-