tomani and use

This commit is contained in:
hamid zarghami
2024-12-31 14:33:23 +03:30
parent afd39d385d
commit ca1537dccc
8 changed files with 64 additions and 20 deletions
+24 -2
View File
@@ -3,12 +3,33 @@ import ProgressCircle from "./progress-circle"
import { AwardsResponse } from "../../types" import { AwardsResponse } from "../../types"
import { FC } from "react" import { FC } from "react"
import { formatDateToPersian } from "../../utility/getDate" 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 = { type Props = {
award: AwardsResponse award: any
} }
export const AwardNotComplete: FC<Props> = ({ award }) => { export const AwardNotComplete: FC<Props> = ({ 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 ( return (
<div className="w-full flex flex-col lg:items-center gap-5 bg-auth-form rounded-[40px] h-full relative p-[18px]"> <div className="w-full flex flex-col lg:items-center gap-5 bg-auth-form rounded-[40px] h-full relative p-[18px]">
<div className="flex flex-row items-center justify-between w-full"> <div className="flex flex-row items-center justify-between w-full">
@@ -16,7 +37,8 @@ export const AwardNotComplete: FC<Props> = ({ award }) => {
<p className="font-normal text-lg text-primary-text-color">{award?.score}</p> <p className="font-normal text-lg text-primary-text-color">{award?.score}</p>
<Cup className="size-4" color="#11212D" /> <Cup className="size-4" color="#11212D" />
</div> </div>
<ProgressCircle percentage={75} /> <button onClick={handleUse} className="w-fit ">استفاده</button>
{/* <ProgressCircle percentage={75} /> */}
</div> </div>
<div className="flex flex-col items-start gap-3"> <div className="flex flex-col items-start gap-3">
<p className="font-normal text-base text-primary-text-color" style={{ fontFamily: "vazirmatn" }}>{award?.desc?.length >= 70 ? `${award?.desc?.slice(0, 70)} ...` : award?.desc}</p> <p className="font-normal text-base text-primary-text-color" style={{ fontFamily: "vazirmatn" }}>{award?.desc?.length >= 70 ? `${award?.desc?.slice(0, 70)} ...` : award?.desc}</p>
+12 -3
View File
@@ -10,7 +10,7 @@ export const AwardComplete: FC<Props> = ({ award }) => {
return ( return (
<div className="flex flex-col w-full h-full justify-between gap-10 bg-auth-form p-[18px] rounded-[40px]"> <div className="flex flex-col w-full h-full justify-between gap-10 bg-auth-form p-[18px] rounded-[40px]">
<div className="flex flex-col gap-3"> <div className="flex flex-col gap-3">
<p className="font-normal text-lg text-secondary-text-color">{award?.req?.desc}</p> <p className="font-normal text-lg text-secondary-text-color">{award?.title}</p>
<p className="font-normal text-base text-secondary-text-color">{formatDateToPersian(award?.expireDate, "jYYYY/jMM/jD")}</p> <p className="font-normal text-base text-secondary-text-color">{formatDateToPersian(award?.expireDate, "jYYYY/jMM/jD")}</p>
</div> </div>
<div className="flex flex-row justify-between items-center"> <div className="flex flex-row justify-between items-center">
@@ -18,8 +18,17 @@ export const AwardComplete: FC<Props> = ({ award }) => {
<p className="font-normal text-lg text-secondary-text-color">{award?.score}</p> <p className="font-normal text-lg text-secondary-text-color">{award?.score}</p>
<Cup className="size-4" color="#777577" /> <Cup className="size-4" color="#777577" />
</div> </div>
<div className="size-10 flex items-center justify-center bg-white rounded-full cursor-pointer"> <div className="h-10 px-4 flex items-center justify-center bg-white rounded-full cursor-pointer">
<Transmit className="size-5" color="#777577" /> {
award.req.status === 0 ?
<div className="text-orange-300">
منتظر تایید
</div>
:
<div className="text-green-400">
تایید شده
</div>
}
</div> </div>
</div> </div>
</div> </div>
+7 -4
View File
@@ -23,9 +23,9 @@ export const Awards = () => {
}, [error]); }, [error]);
useEffect(() => { useEffect(() => {
const awardsTemp: number = data?.data?.length; const awardsTemp: number = data?.data?.awards?.length;
const tempScores: any = data?.data?.filter((award: AwardsResponse) => award?.status === 1); const tempScores: any = data?.data?.score?.score
const myScore = tempScores?.reduce((totalScore: number, award: AwardsResponse) => totalScore + award?.score, 0); const myScore = data?.data?.score?.score
setStatus({ setStatus({
awards: awardsTemp, awards: awardsTemp,
my_score: myScore my_score: myScore
@@ -40,7 +40,10 @@ export const Awards = () => {
<p className="font-normal text-base text-primary-text-color">امتیازهای من: {status?.my_score}</p> <p className="font-normal text-base text-primary-text-color">امتیازهای من: {status?.my_score}</p>
</div> </div>
<div className="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 gap-6"> <div className="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 gap-6">
{data?.data?.map((award: AwardsResponse, index: number) => award?.status === 0 ? <AwardNotComplete key={index} award={award} /> : <AwardComplete key={index} award={award} />)} {data?.data?.awards?.map((award: AwardsResponse, index: number) => award?.status === 0 ?
<AwardNotComplete key={index} award={award} />
:
<AwardComplete key={index} award={award} />)}
</div> </div>
</div> </div>
); );
+11 -3
View File
@@ -13,7 +13,8 @@ type Props = {
tableStatus?: boolean, tableStatus?: boolean,
isLoading?: boolean, isLoading?: boolean,
totalData?: number, totalData?: number,
tableScore?: number tableScore?: number,
totalScore?: number
} }
type ADSortType = { type ADSortType = {
@@ -21,7 +22,7 @@ type ADSortType = {
value: 1 | -1 value: 1 | -1
} }
export const Table: FC<Props> = ({ columns, data, tableStatus = false, tableScore = 0, isLoading = false, totalData = 0 }) => { export const Table: FC<Props> = ({ columns, data, tableStatus = false, tableScore = 0, isLoading = false, totalData = 0, totalScore = 0 }) => {
const [aDSort, setADSort] = useState<ADSortType>({ const [aDSort, setADSort] = useState<ADSortType>({
key: "", key: "",
value: -1 value: -1
@@ -76,7 +77,14 @@ export const Table: FC<Props> = ({ columns, data, tableStatus = false, tableScor
<ComboBox placeholder={params?.rows.toString()} className="bg-auth-form" data={tableRows} mode="table" /> <ComboBox placeholder={params?.rows.toString()} className="bg-auth-form" data={tableRows} mode="table" />
</div> </div>
</div> </div>
<div className="w-full flex justify-start items-end text-sm lg:text-lg text-primary-text-color font-normal -mb-7 pl-2">{tableStatus && `امتیاز من : ${tableScore}`}</div> <div className="w-full flex gap-10 justify-start items-end text-sm lg:text-lg text-primary-text-color font-normal -mb-7 pl-2">
<div>
{tableStatus && `امتیاز حال حاضر : ${tableScore}`}
</div>
<div>
{`امتیاز کل : ${totalScore}`}
</div>
</div>
<div className="block max-w-full min-h-max overflow-x-auto overflow-y-hidden bg-auth-form rounded-[40px] shadow-sm p-4 pb-0 xl:p-9 xl:pb-0 relative"> <div className="block max-w-full min-h-max overflow-x-auto overflow-y-hidden bg-auth-form rounded-[40px] shadow-sm p-4 pb-0 xl:p-9 xl:pb-0 relative">
<table> <table>
<thead className="border-b border-b-secondary-color"> <thead className="border-b border-b-secondary-color">
+4 -3
View File
@@ -9,7 +9,7 @@ import { handleError } from "../../utility/error-handle"
export const Score = () => { export const Score = () => {
const { params } = useParamsStore() const { params } = useParamsStore()
const [data, setData] = useState<ScoreResponse>({ const [data, setData] = useState<any>({
data: [], data: [],
total: 0, total: 0,
score: 0 score: 0
@@ -26,7 +26,8 @@ export const Score = () => {
setData({ setData({
data: res?.data?.data, data: res?.data?.data,
total: res?.data?.total, total: res?.data?.total,
score: res?.data?.score score: res?.data?.score,
totalScore: res?.data?.totalScore,
}) })
}, },
onError: (err: any) => handleError(err) onError: (err: any) => handleError(err)
@@ -34,6 +35,6 @@ export const Score = () => {
}) })
}, [mutate, params]) }, [mutate, params])
return ( return (
<Table columns={scoresCol} data={data?.data} tableStatus={true} tableScore={data?.score} isLoading={isPending} totalData={data?.total} /> <Table columns={scoresCol} data={data?.data} tableStatus={true} totalScore={data?.totalScore} tableScore={data?.score} isLoading={isPending} totalData={data?.total} />
) )
} }
+4 -3
View File
@@ -1,6 +1,7 @@
import { AwardsResponse } from "../../types"; import { AwardsResponse } from "../../types";
import axiosInstance from "../axios"; import axiosInstance from "../axios";
export const getAwardsList = () =>
export const getAwardsList = () => axiosInstance.get<AwardsResponse[] | AwardsResponse | [], any>("/gps/award") axiosInstance.get<AwardsResponse[] | AwardsResponse | [], any>("/gps/award");
export const useAward = (params: any) =>
axiosInstance.post<any>("/gps/award-request", params);
+1 -1
View File
@@ -1,7 +1,7 @@
import axios from "axios"; import axios from "axios";
const axiosInstance = axios.create({ 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", baseURL: "https://asan-service.com/api",
}); });
+1 -1
View File
@@ -9,7 +9,7 @@ const columnConfigs: colConfig[] | [] = [
cellRenderer: (info) => info.getValue() === 1 ? <ShieldTick color="#11212D" className="flex w-full" /> : <ShieldCross color="#E51717" className="flex w-full" /> cellRenderer: (info) => info.getValue() === 1 ? <ShieldTick color="#11212D" className="flex w-full" /> : <ShieldCross color="#E51717" className="flex w-full" />
}, },
{ {
accessor: "deviceId.dollarProfit", header: "دلار" accessor: "deviceId.profit", header: "سود تومانی"
}, },
{ accessor: "deviceId.score", header: "امتیاز" }, { accessor: "deviceId.score", header: "امتیاز" },
{ accessor: "deviceId.model", header: "مدل دستگاه" }, { accessor: "deviceId.model", header: "مدل دستگاه" },