add score and total score + update score after submit imai
This commit is contained in:
@@ -39,7 +39,19 @@ export const StatusBoxItem: FC<Props> = ({ item, detail = false }) => {
|
|||||||
تومان
|
تومان
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{item?.name !== "coin" && item?.name !== "dollar" && item?.value}
|
{item?.name === "score-total" && (
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
<div className="flex items-center gap-x-2">
|
||||||
|
<span className="text-sm font-normal text-secondary-text-color">امتیاز فعلی:</span>
|
||||||
|
<span className="font-medium text-[28px] text-primary-text-color">{item?.value ?? 0}</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-x-2">
|
||||||
|
<span className="text-sm font-normal text-secondary-text-color">کل امتیاز:</span>
|
||||||
|
<span className="font-medium text-[28px] text-primary-text-color">{item?.secondaryValue ?? 0}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{item?.name !== "coin" && item?.name !== "dollar" && item?.name !== "score-total" && item?.value}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { Button } from "@headlessui/react"
|
|
||||||
import { Input } from "../common/input"
|
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 { checkIMEI } from "../../services/api/imei"
|
||||||
import { ButtonComponent } from "../common/button"
|
import { ButtonComponent } from "../common/button"
|
||||||
import { Controller, SubmitHandler, useForm } from "react-hook-form"
|
import { Controller, SubmitHandler, useForm } from "react-hook-form"
|
||||||
@@ -10,8 +9,12 @@ import { checkIMEISchema } from "../../schema"
|
|||||||
import { ErrorComponent } from "../common/error"
|
import { ErrorComponent } from "../common/error"
|
||||||
import toast from "react-hot-toast"
|
import toast from "react-hot-toast"
|
||||||
import { handleError } from "../../utility/error-handle"
|
import { handleError } from "../../utility/error-handle"
|
||||||
|
import { getUsersInformation } from "../../services/api/user"
|
||||||
|
import { useUserStore } from "../../store/user"
|
||||||
|
|
||||||
export const Imei = () => {
|
export const Imei = () => {
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
const { updateUser } = useUserStore()
|
||||||
const {
|
const {
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
formState: { errors },
|
formState: { errors },
|
||||||
@@ -23,10 +26,21 @@ export const Imei = () => {
|
|||||||
mutationFn: checkIMEI,
|
mutationFn: checkIMEI,
|
||||||
mutationKey: ["IMEI"]
|
mutationKey: ["IMEI"]
|
||||||
})
|
})
|
||||||
|
const { mutate: userMutate } = useMutation({
|
||||||
|
mutationFn: getUsersInformation,
|
||||||
|
mutationKey: ["user"]
|
||||||
|
})
|
||||||
const handleCheckIMEI: SubmitHandler<CheckIMEI> = async (data) => {
|
const handleCheckIMEI: SubmitHandler<CheckIMEI> = async (data) => {
|
||||||
await mutate(data, {
|
await mutate(data, {
|
||||||
onSuccess: (res: any) => {
|
onSuccess: (res: any) => {
|
||||||
toast.success("کد IMEI معتبر است")
|
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)
|
onError: (err: any) => handleError(err)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ import { StatusBoxItemInterface } from "../../types"
|
|||||||
import { StatusBoxItem } from "../common/status-box-items"
|
import { StatusBoxItem } from "../common/status-box-items"
|
||||||
import { getOverviewDetails } from "../../services/api/overview"
|
import { getOverviewDetails } from "../../services/api/overview"
|
||||||
import { useEffect, useState } from "react"
|
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 { HomeStatusSkeleton } from "./status-skeleton"
|
||||||
import { handleError } from "../../utility/error-handle"
|
import { handleError } from "../../utility/error-handle"
|
||||||
|
import { useUserStore } from "../../store/user"
|
||||||
|
|
||||||
export const StatusBox = () => {
|
export const StatusBox = () => {
|
||||||
|
const { user } = useUserStore()
|
||||||
const { data, isLoading, error } = useQuery({
|
const { data, isLoading, error } = useQuery({
|
||||||
queryKey: ['overview'],
|
queryKey: ['overview'],
|
||||||
queryFn: getOverviewDetails
|
queryFn: getOverviewDetails
|
||||||
@@ -34,13 +36,22 @@ export const StatusBox = () => {
|
|||||||
icon: <Star color="#292D32" variant="Bold" className="size-[40px]" />,
|
icon: <Star color="#292D32" variant="Bold" className="size-[40px]" />,
|
||||||
value: data?.data?.user?.score
|
value: data?.data?.user?.score
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "score-total",
|
||||||
|
title: "امتیاز",
|
||||||
|
icon: <Star color="#292D32" variant="Bold" className="size-[40px]" />,
|
||||||
|
value: user?.score,
|
||||||
|
secondaryValue: user?.totalScore
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "radar",
|
name: "radar",
|
||||||
title: "تعداد کل دستگاه ثبت شده موفق",
|
title: "تعداد کل دستگاه ثبت شده موفق",
|
||||||
icon: <Radar color="#292D32" variant="Bold" className="size-[40px]" />,
|
icon: <Radar color="#292D32" variant="Bold" className="size-[40px]" />,
|
||||||
value: data?.data?.installedDevice
|
value: data?.data?.installedDevice
|
||||||
}])
|
},
|
||||||
}, [data])
|
|
||||||
|
])
|
||||||
|
}, [data, user])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
handleError(error)
|
handleError(error)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ export type OverviewUser = {
|
|||||||
walletBalance: number,
|
walletBalance: number,
|
||||||
dollarBalance: number,
|
dollarBalance: number,
|
||||||
score: number,
|
score: number,
|
||||||
|
totalScore: number,
|
||||||
_id: string,
|
_id: string,
|
||||||
id: string
|
id: string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ const defaultParams: UserInterface = {
|
|||||||
profilePic: "",
|
profilePic: "",
|
||||||
province_name: "",
|
province_name: "",
|
||||||
score: 0,
|
score: 0,
|
||||||
|
totalScore: 0,
|
||||||
shopName: "",
|
shopName: "",
|
||||||
updated_at: "",
|
updated_at: "",
|
||||||
walletBalance: 0,
|
walletBalance: 0,
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ export interface StatusBoxItemInterface {
|
|||||||
icon: React.ReactNode;
|
icon: React.ReactNode;
|
||||||
value: number;
|
value: number;
|
||||||
detail?: boolean;
|
detail?: boolean;
|
||||||
|
secondaryValue?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateUserInterface {
|
export interface UpdateUserInterface {
|
||||||
@@ -247,6 +248,7 @@ type OverviewUser = {
|
|||||||
walletBalance: number;
|
walletBalance: number;
|
||||||
dollarBalance: number;
|
dollarBalance: number;
|
||||||
score: number;
|
score: number;
|
||||||
|
totalScore: number;
|
||||||
_id: string;
|
_id: string;
|
||||||
id: string;
|
id: string;
|
||||||
};
|
};
|
||||||
@@ -324,6 +326,7 @@ export interface UserInterface {
|
|||||||
profilePic: string;
|
profilePic: string;
|
||||||
province_name: string;
|
province_name: string;
|
||||||
score: number;
|
score: number;
|
||||||
|
totalScore: number;
|
||||||
shopName: string;
|
shopName: string;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
walletBalance: number;
|
walletBalance: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user