diff --git a/components/dashboard/userAccount/sidebars/transactions/Card.js b/components/dashboard/userAccount/sidebars/transactions/Card.js index 77b78a2..3b7a3bc 100644 --- a/components/dashboard/userAccount/sidebars/transactions/Card.js +++ b/components/dashboard/userAccount/sidebars/transactions/Card.js @@ -1,39 +1,36 @@ -import CircularLoading from "@/app/component/loading/Circular"; import TextLoading from "@/app/component/loading/Text"; -import Image from "next/image"; -import { convertTimestampToJalali, convertTimestampToTime } from "@/helper"; +import { convertTimestampToJalali } from "@/helper"; import Link from "next/link"; +const PAYMENT_STATUS = { + success: { label: "پرداخت شده", cls: "bg-[#E8FADD] text-[#75E22E]" }, + pending: { label: "در انتظار", cls: "bg-[#FFF3DD] text-[#FDBA35]" }, + failed: { label: "ناموفق", cls: "bg-[#FFE3E2] text-[#FF5450]" }, + cancelled: { label: "لغو شده", cls: "bg-[#FFE3E2] text-[#FF5450]" }, + refunded: { label: "بازگشت وجه", cls: "bg-[#EFEFEF] text-[#616161]" }, +}; + +const TYPE_LABELS = { + appointment: "نوبت", + subscription: "اشتراک", + sms_wallet: "کیف پول پیامک", +}; + function Card({ data, loading }) { + const status = PAYMENT_STATUS[data.status] || { label: data.status, cls: "bg-[#FFE3E2] text-[#FF5450]" }; + return (
  • -
    - -

    - {data.appointment_details?.doctor_name || "--"} -

    -
    -
    + +

    + {TYPE_LABELS[data.type] || data.type || "--"} +

    +
    -
    - {data.status === "received" - ? "پرداخت شده" - : data.status === "pending" - ? "در انتظار" - : "لغو شده"} +
    + {status.label}
    @@ -44,43 +41,28 @@ function Card({ data, loading }) {

    شناسه:

    -

    {data.id}

    +

    {data.order_id || "--"}

  • -

    - تاریخ نوبت: -

    +

    تاریخ:

    - {convertTimestampToJalali(data.appointment_details?.start_time)} -

    -
    -
  • - -
  • - -

    ساعت نوبت:

    -
    - -

    - {convertTimestampToTime(data.appointment_details?.start_time)} + {convertTimestampToJalali(data.created_at)}

  • -

    - مبلغ: -

    +

    مبلغ:

    - {data.amount ? data.amount.toLocaleString('fa-IR') : "--"} تومان + {data.amount_rials ? Math.round(data.amount_rials / 10).toLocaleString("fa-IR") : "--"} تومان

  • diff --git a/components/dashboard/userAccount/sidebars/transactions/List.js b/components/dashboard/userAccount/sidebars/transactions/List.js index 37b1775..e5c237a 100644 --- a/components/dashboard/userAccount/sidebars/transactions/List.js +++ b/components/dashboard/userAccount/sidebars/transactions/List.js @@ -5,42 +5,57 @@ import Card from "./Card"; import TextLoading from "@/app/component/loading/Text"; import CustomLoading from "@/app/component/loading/Custom"; import CircularLoading from "@/app/component/loading/Circular"; -import { convertTimestampToJalali, convertTimestampToTime } from "@/helper"; +import { convertTimestampToJalali } from "@/helper"; import Pagination from "@/app/component/Pagination"; import Link from "next/link"; -function List({ user, loading, page, totalPages, onPageChange }) { - const tableHead = [ - "ردیف", - "شناسه", - "نام پزشک", - "تاریخ", - "ساعت", - "مبلغ (تومان)", - "وضعیت", - ]; +const PAYMENT_STATUS = { + success: { label: "پرداخت شده", cls: "bg-[#E8FADD] text-[#75E22E]" }, + pending: { label: "در انتظار", cls: "bg-[#FFF3DD] text-[#FDBA35]" }, + failed: { label: "ناموفق", cls: "bg-[#FFE3E2] text-[#FF5450]" }, + cancelled: { label: "لغو شده", cls: "bg-[#FFE3E2] text-[#FF5450]" }, + refunded: { label: "بازگشت وجه", cls: "bg-[#EFEFEF] text-[#616161]" }, +}; + +const TYPE_LABELS = { + appointment: "نوبت", + subscription: "اشتراک", + sms_wallet: "کیف پول پیامک", +}; + +function List({ payments, loading, page, totalPages, onPageChange }) { + const rows = Array.isArray(payments) ? payments : []; + const tableHead = ["ردیف", "شناسه پرداخت", "نوع", "تاریخ", "مبلغ (تومان)", "وضعیت"]; const centerTable = [0, 4, 5]; + if (!loading && rows.length === 0) { + return ( +

    + تراکنشی ثبت نشده است. +

    + ); + } + return (
    - {user.turns.done.map((row, idx) => ( + {rows.map((row, idx) => ( - {idx + 1} + {(page - 1) * 10 + idx + 1} - - {row.id} + + {row.order_id || "--"} - - {row.appointment_details?.doctor_name || "--"} + + {TYPE_LABELS[row.type] || row.type || "--"} - {convertTimestampToJalali(row.appointment_details?.start_time)} + {convertTimestampToJalali(row.created_at)} - {convertTimestampToTime(row.appointment_details?.start_time)} - - - - - {row.amount ? row.amount.toLocaleString('fa-IR') : "--"} + {row.amount_rials ? Math.round(row.amount_rials / 10).toLocaleString("fa-IR") : "--"}
    - {row.status === "received" - ? "پرداخت شده" - : row.status === "pending" - ? "در انتظار" - : "لغو شده"} + {(PAYMENT_STATUS[row.status] || { label: row.status }).label}
    @@ -105,7 +99,7 @@ function List({ user, loading, page, totalPages, onPageChange }) {
    diff --git a/components/dashboard/userAccount/sidebars/transactions/index.js b/components/dashboard/userAccount/sidebars/transactions/index.js index ea4d905..2a8ea96 100644 --- a/components/dashboard/userAccount/sidebars/transactions/index.js +++ b/components/dashboard/userAccount/sidebars/transactions/index.js @@ -71,7 +71,7 @@ function Transactions({ user, loading }) {