From 49cd5faf9dec4f16c1b452b8369718c3304ff8a8 Mon Sep 17 00:00:00 2001 From: Alihaghighattalab Date: Sat, 17 Aug 2024 11:14:21 +0330 Subject: [PATCH] complete award page - score - transactions not complete --- src/components/awards/award-not-complete.tsx | 17 ++++++++---- src/components/awards/index.tsx | 15 ++++++++-- src/components/score/index.tsx | 20 +++++++++----- src/components/transactions/index.tsx | 20 +++++++++----- src/services/api/awards.ts | 15 ++-------- src/services/api/score.ts | 7 ++--- src/services/api/transactions.ts | 29 +++++++++++++++++++- src/types/index.ts | 12 ++++++++ src/utility/getDate.tsx | 7 +++-- src/utility/transactions.tsx | 4 +-- 10 files changed, 101 insertions(+), 45 deletions(-) diff --git a/src/components/awards/award-not-complete.tsx b/src/components/awards/award-not-complete.tsx index c6a5c00..79813d8 100644 --- a/src/components/awards/award-not-complete.tsx +++ b/src/components/awards/award-not-complete.tsx @@ -1,20 +1,27 @@ import { Calendar2, Cup } from "iconsax-react" import ProgressCircle from "./progress-circle" +import { AwardsResponse } from "../../types" +import { FC } from "react" +import { formatDateToPersian } from "../../utility/getDate" -export const AwardNotComplete = () => { +type Props = { + award: AwardsResponse +} + +export const AwardNotComplete: FC = ({ award }) => { return ( -
+
-

75

+

{award?.score}

-

۲۵۰ هزار تومان تخفیف برای اقامت در تمام ویلاها و کلبه های جاجیگا با حداقل رزرو ۲ میلیون تومان

+

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

-

1403/06/12

+

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

diff --git a/src/components/awards/index.tsx b/src/components/awards/index.tsx index 02eb348..d8b92af 100644 --- a/src/components/awards/index.tsx +++ b/src/components/awards/index.tsx @@ -1,7 +1,17 @@ +import { useQuery } from "@tanstack/react-query" import { AwardNotComplete } from "./award-not-complete" -import { AwardComplete } from "./awards-complete" +import { getAwardsList } from "../../services/api/awards" +import { useEffect } from "react" +import { AwardsResponse } from "../../types" export const Awards = () => { + const { data, isLoading } = useQuery({ + queryKey: ["awards"], + queryFn: getAwardsList + }) + + useEffect(() => { console.log("data =>", data?.data) }, [data]) + if (isLoading) return

LOADING...

return (
@@ -9,8 +19,7 @@ export const Awards = () => {

امتیازهای من: 65

- - + {data?.data?.map((award: AwardsResponse) => )}
) diff --git a/src/components/score/index.tsx b/src/components/score/index.tsx index c56617a..2c3606f 100644 --- a/src/components/score/index.tsx +++ b/src/components/score/index.tsx @@ -1,18 +1,24 @@ -import { useState } from "react" +import { useEffect, useState } from "react" import { Table } from "../common/table" import { SortingState } from "@tanstack/react-table" import { scoresCol } from "../../utility/score" +import { useQuery } from "@tanstack/react-query" +import { getScoresList } from "../../services/api/score" export const Score = () => { const [sorting, setSorting] = useState([]) - // const { data, isLoading } = useQuery({ - // queryKey: ["score-list"], - // queryFn: getScoreList - // }) + const { data, isLoading } = useQuery({ + queryKey: ["score-list"], + queryFn: getScoresList + }) - // if (isLoading) return

LOADING ...

+ useEffect(() => { + console.log("data =>", data) + }, [data]) + + if (isLoading) return

LOADING ...

return ( - +
) } \ No newline at end of file diff --git a/src/components/transactions/index.tsx b/src/components/transactions/index.tsx index 3f5e5e6..0d6c7fe 100644 --- a/src/components/transactions/index.tsx +++ b/src/components/transactions/index.tsx @@ -1,18 +1,24 @@ -import { useState } from "react" +import { useEffect, useState } from "react" import { Table } from "../common/table" import { SortingState } from "@tanstack/react-table" import { transactionsCol } from "../../utility/transactions" +import { getTransactionsList } from "../../services/api/transactions" +import { useQuery } from "@tanstack/react-query" export const Transactions = () => { const [sorting, setSorting] = useState([]) - // const { data, isLoading } = useQuery({ - // queryKey: ["transactions-list"], - // queryFn: getTransactionsList - // }) + const { data, isLoading } = useQuery({ + queryKey: ["transactions-list"], + queryFn: getTransactionsList + }) - // if (isLoading) return

LOADING ....

+ useEffect(() => { + console.log("data=>", data) + }, [data]) + + if (isLoading) return

LOADING ....

return ( -
+
) } \ No newline at end of file diff --git a/src/services/api/awards.ts b/src/services/api/awards.ts index 9eba7cb..f2fec33 100644 --- a/src/services/api/awards.ts +++ b/src/services/api/awards.ts @@ -1,17 +1,6 @@ +import { AwardsResponse } from "../../types"; import axiosInstance from "../axios"; -export interface AwardsResponse { - _id: string, - score: number, - title: string, - desc: string, - expireDate: string, - created_at: string, - updated_at: string, - __v: number, - id: string -} - -export const getAwardsList = () => axiosInstance.get("/gps/award") +export const getAwardsList = () => axiosInstance.get("/gps/award") diff --git a/src/services/api/score.ts b/src/services/api/score.ts index 22fe2ef..8456e0b 100644 --- a/src/services/api/score.ts +++ b/src/services/api/score.ts @@ -1,6 +1,6 @@ import axiosInstance from "../axios"; -export type ScoreDataResponse = { +export type ScoreData = { _id: string, deviceId: string, score: number, @@ -11,12 +11,11 @@ export type ScoreDataResponse = { id: string } - export interface ScoreResponse { - data: ScoreDataResponse[] | [] + data: ScoreData[] | [] score: number, total: number } -export const getScoresList = () => axiosInstance.get("/gps/score") +export const getScoresList = () => axiosInstance.get("/gps/score") diff --git a/src/services/api/transactions.ts b/src/services/api/transactions.ts index df00f1a..447d1ef 100644 --- a/src/services/api/transactions.ts +++ b/src/services/api/transactions.ts @@ -1,3 +1,30 @@ import axiosInstance from "../axios"; -export const getTransactionsList = () => axiosInstance.get("/gps/transactions") \ No newline at end of file +export interface TransactionsResponse { + data: TransactionsData[] | [] +} + +export interface TransactionsData { + _id: string, + card: TransactionsCard + userId: string, + amount: number, + dollarAmount: number, + status: number, + created_at: string, + updated_at: string, + __v: number, + id: string +} + +export interface TransactionsCard { + _id: string, + holderName: string, + PAN: number, + IBAN: string, + created_at: string, + updated_at: string, + id: string +} + +export const getTransactionsList = () => axiosInstance.get("/gps/transactions") \ No newline at end of file diff --git a/src/types/index.ts b/src/types/index.ts index f6b2360..41a103c 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -206,4 +206,16 @@ export interface RegisterDeviceId { updated_at: string, __v: number, id: string +} + +export interface AwardsResponse { + _id: string, + score: number, + title: string, + desc: string, + expireDate: string, + created_at: string, + updated_at: string, + __v: number, + id: string } \ No newline at end of file diff --git a/src/utility/getDate.tsx b/src/utility/getDate.tsx index 19d67c7..b8b8140 100644 --- a/src/utility/getDate.tsx +++ b/src/utility/getDate.tsx @@ -2,9 +2,10 @@ import moment from "moment-jalaali"; export const getJalaaliDate = () => { const date: Date = new Date() - return moment(date).format('jYYYY/jM/jD') + return moment(date).format('jYYYY/jMM/jDD') } -export const formatDateToPersian = (date: string | Date) => { - return moment(date).format("jYYYY/jM/jD HH:mm") +export const formatDateToPersian = (date: string | Date, format?: string) => { + const formatString = format ? format : "jYYYY/jMM/jDD HH:mm" + return moment(date).format(formatString) } diff --git a/src/utility/transactions.tsx b/src/utility/transactions.tsx index 7e47e56..0db50b5 100644 --- a/src/utility/transactions.tsx +++ b/src/utility/transactions.tsx @@ -8,7 +8,7 @@ import { filterNumber } from "./status"; const columnConfigs: colConfig[] | [] = [ { accessor: "status", header: "وضعیت", - cellRenderer: (info) => info.getValue() ? : + cellRenderer: (info) => info.getValue() === 1 ? : }, { accessor: "amount", header: "مبلغ", @@ -17,7 +17,7 @@ const columnConfigs: colConfig[] | [] = [

تومان

}, - { accessor: "request_date", header: "تاریخ درخواست", cellRenderer: (info) => info.getValue() &&

{info.getValue()}

}, + { accessor: "request_date", header: "تاریخ درخواست", cellRenderer: (info) => info.getValue() &&

{info.getValue()}

}, { accessor: "traking_number", header: "شماره پیگیری" }, { accessor: "deposit_date", header: "تاریخ واریز" }, ];