From b29bbf54b838bd86432e4e580e3e94a026eb2aed Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Tue, 2 Dec 2025 09:27:21 +0330 Subject: [PATCH] add score and total score + update score after submit imai --- src/components/common/status-box-items.tsx | 14 +++++++++++++- src/components/home/imei.tsx | 18 ++++++++++++++++-- src/components/home/status-box.tsx | 17 ++++++++++++++--- src/services/api/overview.ts | 1 + src/store/user.ts | 1 + src/types/index.ts | 3 +++ 6 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/components/common/status-box-items.tsx b/src/components/common/status-box-items.tsx index b3f15e9..bdcd083 100644 --- a/src/components/common/status-box-items.tsx +++ b/src/components/common/status-box-items.tsx @@ -39,7 +39,19 @@ export const StatusBoxItem: FC = ({ item, detail = false }) => { تومان )} - {item?.name !== "coin" && item?.name !== "dollar" && item?.value} + {item?.name === "score-total" && ( +
+
+ امتیاز فعلی: + {item?.value ?? 0} +
+
+ کل امتیاز: + {item?.secondaryValue ?? 0} +
+
+ )} + {item?.name !== "coin" && item?.name !== "dollar" && item?.name !== "score-total" && item?.value} diff --git a/src/components/home/imei.tsx b/src/components/home/imei.tsx index 9c3b76e..e7e3b48 100644 --- a/src/components/home/imei.tsx +++ b/src/components/home/imei.tsx @@ -1,6 +1,5 @@ -import { Button } from "@headlessui/react" import { Input } from "../common/input" -import { useMutation } from "@tanstack/react-query" +import { useMutation, useQueryClient } from "@tanstack/react-query" import { checkIMEI } from "../../services/api/imei" import { ButtonComponent } from "../common/button" import { Controller, SubmitHandler, useForm } from "react-hook-form" @@ -10,8 +9,12 @@ import { checkIMEISchema } from "../../schema" import { ErrorComponent } from "../common/error" import toast from "react-hot-toast" import { handleError } from "../../utility/error-handle" +import { getUsersInformation } from "../../services/api/user" +import { useUserStore } from "../../store/user" export const Imei = () => { + const queryClient = useQueryClient() + const { updateUser } = useUserStore() const { handleSubmit, formState: { errors }, @@ -23,10 +26,21 @@ export const Imei = () => { mutationFn: checkIMEI, mutationKey: ["IMEI"] }) + const { mutate: userMutate } = useMutation({ + mutationFn: getUsersInformation, + mutationKey: ["user"] + }) const handleCheckIMEI: SubmitHandler = async (data) => { await mutate(data, { onSuccess: (res: any) => { toast.success("کد IMEI معتبر است") + queryClient.invalidateQueries({ queryKey: ['overview'] }) + userMutate({}, { + onSuccess: (userRes: any) => { + updateUser(userRes?.data?.user) + }, + onError: (err: any) => handleError(err) + }) }, onError: (err: any) => handleError(err) }) diff --git a/src/components/home/status-box.tsx b/src/components/home/status-box.tsx index 0bd3f6e..faad5c1 100644 --- a/src/components/home/status-box.tsx +++ b/src/components/home/status-box.tsx @@ -3,11 +3,13 @@ import { StatusBoxItemInterface } from "../../types" import { StatusBoxItem } from "../common/status-box-items" import { getOverviewDetails } from "../../services/api/overview" import { useEffect, useState } from "react" -import { Coin1, DollarCircle, Radar, Star } from "iconsax-react" +import { DollarCircle, Radar, Star } from "iconsax-react" import { HomeStatusSkeleton } from "./status-skeleton" import { handleError } from "../../utility/error-handle" +import { useUserStore } from "../../store/user" export const StatusBox = () => { + const { user } = useUserStore() const { data, isLoading, error } = useQuery({ queryKey: ['overview'], queryFn: getOverviewDetails @@ -34,13 +36,22 @@ export const StatusBox = () => { icon: , value: data?.data?.user?.score }, + { + name: "score-total", + title: "امتیاز", + icon: , + value: user?.score, + secondaryValue: user?.totalScore + }, { name: "radar", title: "تعداد کل دستگاه ثبت شده موفق", icon: , value: data?.data?.installedDevice - }]) - }, [data]) + }, + + ]) + }, [data, user]) useEffect(() => { handleError(error) diff --git a/src/services/api/overview.ts b/src/services/api/overview.ts index 32da8ee..831b3c6 100644 --- a/src/services/api/overview.ts +++ b/src/services/api/overview.ts @@ -4,6 +4,7 @@ export type OverviewUser = { walletBalance: number, dollarBalance: number, score: number, + totalScore: number, _id: string, id: string } diff --git a/src/store/user.ts b/src/store/user.ts index cdad9d2..f91ac9f 100644 --- a/src/store/user.ts +++ b/src/store/user.ts @@ -21,6 +21,7 @@ const defaultParams: UserInterface = { profilePic: "", province_name: "", score: 0, + totalScore: 0, shopName: "", updated_at: "", walletBalance: 0, diff --git a/src/types/index.ts b/src/types/index.ts index 93ec05b..a86e301 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -65,6 +65,7 @@ export interface StatusBoxItemInterface { icon: React.ReactNode; value: number; detail?: boolean; + secondaryValue?: number; } export interface UpdateUserInterface { @@ -247,6 +248,7 @@ type OverviewUser = { walletBalance: number; dollarBalance: number; score: number; + totalScore: number; _id: string; id: string; }; @@ -324,6 +326,7 @@ export interface UserInterface { profilePic: string; province_name: string; score: number; + totalScore: number; shopName: string; updated_at: string; walletBalance: number;