From ca1537dccc8580e6771749cf04c8c861e289fc77 Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Tue, 31 Dec 2024 14:33:23 +0330 Subject: [PATCH] tomani and use --- src/components/awards/award-not-complete.tsx | 26 ++++++++++++++++++-- src/components/awards/awards-complete.tsx | 15 ++++++++--- src/components/awards/index.tsx | 11 ++++++--- src/components/common/table.tsx | 14 ++++++++--- src/components/score/index.tsx | 7 +++--- src/services/api/awards.ts | 7 +++--- src/services/axios/index.ts | 2 +- src/utility/reports.tsx | 2 +- 8 files changed, 64 insertions(+), 20 deletions(-) diff --git a/src/components/awards/award-not-complete.tsx b/src/components/awards/award-not-complete.tsx index a9e612d..98bb010 100644 --- a/src/components/awards/award-not-complete.tsx +++ b/src/components/awards/award-not-complete.tsx @@ -3,12 +3,33 @@ import ProgressCircle from "./progress-circle" import { AwardsResponse } from "../../types" import { FC } from "react" import { formatDateToPersian } from "../../utility/getDate" +import { useMutation } from "@tanstack/react-query" +import { useAward } from "../../services/api/awards" +import toast from "react-hot-toast" type Props = { - award: AwardsResponse + award: any } export const AwardNotComplete: FC = ({ award }) => { + + const { mutate, isPending } = useMutation({ + mutationFn: useAward, + mutationKey: ["IMEI"] + }) + + const handleUse = () => { + mutate({ awardId: award?.id }, { + onSuccess: (res: any) => { + toast.success("درخواست استفاده از جایزه ثبت شد") + window.location.reload() + }, + onError: (err: any) => { + console.log(err) + } + }) + } + return (
@@ -16,7 +37,8 @@ export const AwardNotComplete: FC = ({ award }) => {

{award?.score}

- + + {/* */}

{award?.desc?.length >= 70 ? `${award?.desc?.slice(0, 70)} ...` : award?.desc}

diff --git a/src/components/awards/awards-complete.tsx b/src/components/awards/awards-complete.tsx index 52df6b8..2b24174 100644 --- a/src/components/awards/awards-complete.tsx +++ b/src/components/awards/awards-complete.tsx @@ -10,7 +10,7 @@ export const AwardComplete: FC = ({ award }) => { return (
-

{award?.req?.desc}

+

{award?.title}

{formatDateToPersian(award?.expireDate, "jYYYY/jMM/jD")}

@@ -18,8 +18,17 @@ export const AwardComplete: FC = ({ award }) => {

{award?.score}

-
- +
+ { + award.req.status === 0 ? +
+ منتظر تایید +
+ : +
+ تایید شده +
+ }
diff --git a/src/components/awards/index.tsx b/src/components/awards/index.tsx index 4b87ad5..316c1ea 100644 --- a/src/components/awards/index.tsx +++ b/src/components/awards/index.tsx @@ -23,9 +23,9 @@ export const Awards = () => { }, [error]); useEffect(() => { - const awardsTemp: number = data?.data?.length; - const tempScores: any = data?.data?.filter((award: AwardsResponse) => award?.status === 1); - const myScore = tempScores?.reduce((totalScore: number, award: AwardsResponse) => totalScore + award?.score, 0); + const awardsTemp: number = data?.data?.awards?.length; + const tempScores: any = data?.data?.score?.score + const myScore = data?.data?.score?.score setStatus({ awards: awardsTemp, my_score: myScore @@ -40,7 +40,10 @@ export const Awards = () => {

امتیازهای من: {status?.my_score}

- {data?.data?.map((award: AwardsResponse, index: number) => award?.status === 0 ? : )} + {data?.data?.awards?.map((award: AwardsResponse, index: number) => award?.status === 0 ? + + : + )}
); diff --git a/src/components/common/table.tsx b/src/components/common/table.tsx index 9d14d96..c9acef6 100644 --- a/src/components/common/table.tsx +++ b/src/components/common/table.tsx @@ -13,7 +13,8 @@ type Props = { tableStatus?: boolean, isLoading?: boolean, totalData?: number, - tableScore?: number + tableScore?: number, + totalScore?: number } type ADSortType = { @@ -21,7 +22,7 @@ type ADSortType = { value: 1 | -1 } -export const Table: FC = ({ columns, data, tableStatus = false, tableScore = 0, isLoading = false, totalData = 0 }) => { +export const Table: FC = ({ columns, data, tableStatus = false, tableScore = 0, isLoading = false, totalData = 0, totalScore = 0 }) => { const [aDSort, setADSort] = useState({ key: "", value: -1 @@ -76,7 +77,14 @@ export const Table: FC = ({ columns, data, tableStatus = false, tableScor -
{tableStatus && `امتیاز من : ${tableScore}`}
+
+
+ {tableStatus && `امتیاز حال حاضر : ${tableScore}`} +
+
+ {`امتیاز کل : ${totalScore}`} +
+
diff --git a/src/components/score/index.tsx b/src/components/score/index.tsx index be0380c..0b0b2d0 100644 --- a/src/components/score/index.tsx +++ b/src/components/score/index.tsx @@ -9,7 +9,7 @@ import { handleError } from "../../utility/error-handle" export const Score = () => { const { params } = useParamsStore() - const [data, setData] = useState({ + const [data, setData] = useState({ data: [], total: 0, score: 0 @@ -26,7 +26,8 @@ export const Score = () => { setData({ data: res?.data?.data, total: res?.data?.total, - score: res?.data?.score + score: res?.data?.score, + totalScore: res?.data?.totalScore, }) }, onError: (err: any) => handleError(err) @@ -34,6 +35,6 @@ export const Score = () => { }) }, [mutate, params]) return ( -
+
) } \ No newline at end of file diff --git a/src/services/api/awards.ts b/src/services/api/awards.ts index f2fec33..bc03bea 100644 --- a/src/services/api/awards.ts +++ b/src/services/api/awards.ts @@ -1,6 +1,7 @@ import { AwardsResponse } from "../../types"; import axiosInstance from "../axios"; - -export const getAwardsList = () => axiosInstance.get("/gps/award") - +export const getAwardsList = () => + axiosInstance.get("/gps/award"); +export const useAward = (params: any) => + axiosInstance.post("/gps/award-request", params); diff --git a/src/services/axios/index.ts b/src/services/axios/index.ts index 9c7c3e2..44a42e0 100644 --- a/src/services/axios/index.ts +++ b/src/services/axios/index.ts @@ -1,7 +1,7 @@ import axios from "axios"; const axiosInstance = axios.create({ - // baseURL: "http://192.168.0.217:7420/api", + // baseURL: "http://192.168.0.243:7420/api", baseURL: "https://asan-service.com/api", }); diff --git a/src/utility/reports.tsx b/src/utility/reports.tsx index d4047b7..9b39e86 100644 --- a/src/utility/reports.tsx +++ b/src/utility/reports.tsx @@ -9,7 +9,7 @@ const columnConfigs: colConfig[] | [] = [ cellRenderer: (info) => info.getValue() === 1 ? : }, { - accessor: "deviceId.dollarProfit", header: "دلار" + accessor: "deviceId.profit", header: "سود تومانی" }, { accessor: "deviceId.score", header: "امتیاز" }, { accessor: "deviceId.model", header: "مدل دستگاه" },