mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-11-05 19:27:19 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dc10fa6be4 | |||
| 39e84723b1 | |||
| 19043aa692 | |||
| f2a17d522b | |||
| 43b8e22196 |
@@ -1,5 +1,12 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## <small>0.2.2 (2025-09-20)</small>
|
||||||
|
|
||||||
|
* refactor: remove table captions from all tables 🔧 ([39e8472](https://github.com/i701/sarlink-portal/commit/39e8472))
|
||||||
|
* fix: hide account information once the payment is verified/expired/cancelled 🔧 ([f2a17d5](https://github.com/i701/sarlink-portal/commit/f2a17d5))
|
||||||
|
* fix: remove pagination if there is only 1 page 🔧 ([43b8e22](https://github.com/i701/sarlink-portal/commit/43b8e22))
|
||||||
|
* fix: set 100 MVR for default wallet topup amount 🔧 ([19043aa](https://github.com/i701/sarlink-portal/commit/19043aa))
|
||||||
|
|
||||||
## <small>0.2.1 (2025-09-20)</small>
|
## <small>0.2.1 (2025-09-20)</small>
|
||||||
|
|
||||||
* fix: add release script 🔧 ([e5298aa](https://github.com/i701/sarlink-portal/commit/e5298aa))
|
* fix: add release script 🔧 ([e5298aa](https://github.com/i701/sarlink-portal/commit/e5298aa))
|
||||||
|
|||||||
@@ -1,78 +1,76 @@
|
|||||||
import { Skeleton } from "@/components/ui/skeleton";
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCaption,
|
TableCell,
|
||||||
TableCell,
|
TableFooter,
|
||||||
TableFooter,
|
TableHead,
|
||||||
TableHead,
|
TableHeader,
|
||||||
TableHeader,
|
TableRow,
|
||||||
TableRow,
|
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
export default function DevicesTableSkeleton() {
|
export default function DevicesTableSkeleton() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="hidden sm:block">
|
<div className="hidden sm:block">
|
||||||
<Table className="overflow-scroll">
|
<Table className="overflow-scroll">
|
||||||
<TableCaption>Table of all devices.</TableCaption>
|
<TableHeader>
|
||||||
<TableHeader>
|
<TableRow>
|
||||||
<TableRow>
|
<TableHead>Device Name</TableHead>
|
||||||
<TableHead>Device Name</TableHead>
|
<TableHead>MAC Address</TableHead>
|
||||||
<TableHead>MAC Address</TableHead>
|
<TableHead>#</TableHead>
|
||||||
<TableHead>#</TableHead>
|
</TableRow>
|
||||||
</TableRow>
|
</TableHeader>
|
||||||
</TableHeader>
|
<TableBody className="overflow-scroll">
|
||||||
<TableBody className="overflow-scroll">
|
{Array.from({ length: 10 }).map((_, i) => (
|
||||||
{Array.from({ length: 10 }).map((_, i) => (
|
<TableRow key={`${i + 1}`}>
|
||||||
<TableRow key={`${i + 1}`}>
|
<TableCell>
|
||||||
<TableCell>
|
<Skeleton className="w-full h-10 rounded" />
|
||||||
<Skeleton className="w-full h-10 rounded" />
|
</TableCell>
|
||||||
</TableCell>
|
<TableCell>
|
||||||
<TableCell>
|
<Skeleton className="w-full h-10 rounded" />
|
||||||
<Skeleton className="w-full h-10 rounded" />
|
</TableCell>
|
||||||
</TableCell>
|
<TableCell>
|
||||||
<TableCell>
|
<Skeleton className="w-full h-10 rounded" />
|
||||||
<Skeleton className="w-full h-10 rounded" />
|
</TableCell>
|
||||||
</TableCell>
|
</TableRow>
|
||||||
</TableRow>
|
))}
|
||||||
))}
|
</TableBody>
|
||||||
</TableBody>
|
<TableFooter>
|
||||||
<TableFooter>
|
<TableRow>
|
||||||
<TableRow>
|
<TableCell colSpan={2}>
|
||||||
<TableCell colSpan={2}>
|
<Skeleton className="w-full h-4 rounded" />
|
||||||
<Skeleton className="w-full h-4 rounded" />
|
</TableCell>
|
||||||
</TableCell>
|
<TableCell className="text-muted-foreground">
|
||||||
<TableCell className="text-muted-foreground">
|
<Skeleton className="w-20 h-4 rounded" />
|
||||||
<Skeleton className="w-20 h-4 rounded" />
|
</TableCell>
|
||||||
</TableCell>
|
</TableRow>
|
||||||
</TableRow>
|
</TableFooter>
|
||||||
</TableFooter>
|
</Table>
|
||||||
</Table>
|
</div>
|
||||||
</div>
|
<div className="sm:hidden my-4">
|
||||||
<div className="sm:hidden my-4">
|
{Array.from({ length: 10 }).map((_, i) => (
|
||||||
{Array.from({ length: 10 }).map((_, i) => (
|
<DeviceCardSkeleton key={`${i + 1}`} />
|
||||||
<DeviceCardSkeleton key={`${i + 1}`} />
|
))}
|
||||||
))}
|
</div>
|
||||||
</div>
|
</>
|
||||||
</>
|
);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function DeviceCardSkeleton() {
|
function DeviceCardSkeleton() {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex text-sm justify-between items-center my-2 p-4 border rounded-md bg-gray-100",
|
"flex text-sm justify-between items-center my-2 p-4 border rounded-md bg-gray-100",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="font-semibold flex w-full flex-col items-start gap-2 mb-2 relative">
|
<div className="font-semibold flex w-full flex-col items-start gap-2 mb-2 relative">
|
||||||
<Skeleton className="w-32 h-6" />
|
<Skeleton className="w-32 h-6" />
|
||||||
<Skeleton className="w-36 h-6" />
|
<Skeleton className="w-36 h-6" />
|
||||||
<Skeleton className="w-32 h-4" />
|
<Skeleton className="w-32 h-4" />
|
||||||
<Skeleton className="w-40 h-8" />
|
<Skeleton className="w-40 h-8" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,72 +9,72 @@ import { TextShimmer } from "@/components/ui/text-shimmer";
|
|||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { tryCatch } from "@/utils/tryCatch";
|
import { tryCatch } from "@/utils/tryCatch";
|
||||||
export default async function TopupPage({
|
export default async function TopupPage({
|
||||||
params,
|
params,
|
||||||
}: {
|
}: {
|
||||||
params: Promise<{ topupId: string }>;
|
params: Promise<{ topupId: string }>;
|
||||||
}) {
|
}) {
|
||||||
const topupId = (await params).topupId;
|
const topupId = (await params).topupId;
|
||||||
const [error, topup] = await tryCatch(getTopup({ id: topupId }));
|
const [error, topup] = await tryCatch(getTopup({ id: topupId }));
|
||||||
if (error) {
|
if (error) {
|
||||||
if (error.message === "Invalid token.") redirect("/auth/signin");
|
if (error.message === "Invalid token.") redirect("/auth/signin");
|
||||||
return <ClientErrorMessage message={error.message} />;
|
return <ClientErrorMessage message={error.message} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="flex justify-between items-center border rounded-md border-dashed font-bold title-bg py-4 px-4 mb-4 mx-2">
|
<div className="flex justify-between items-center border rounded-md border-dashed font-bold title-bg py-4 px-4 mb-4 mx-2">
|
||||||
<h3 className="text-sarLinkOrange text-2xl">Topup</h3>
|
<h3 className="text-sarLinkOrange text-2xl">Topup</h3>
|
||||||
<div className="flex flex-col gap-4 items-end w-full">
|
<div className="flex flex-col gap-4 items-end w-full">
|
||||||
{!topup.is_expired && topup.paid && topup.status !== "PENDING" && (
|
{!topup.is_expired && topup.paid && topup.status !== "PENDING" && (
|
||||||
<Button
|
<Button
|
||||||
disabled
|
disabled
|
||||||
className={cn(
|
className={cn(
|
||||||
"rounded-md opacity-100! uppercase font-semibold",
|
"rounded-md opacity-100! uppercase font-semibold",
|
||||||
topup?.paid
|
topup?.paid
|
||||||
? "text-green-900 bg-green-500/20"
|
? "text-green-900 bg-green-500/20"
|
||||||
: "text-inherit bg-yellow-400",
|
: "text-inherit bg-yellow-400",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{topup.status}
|
{topup.status}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{topup.status === "PENDING" && !topup.is_expired && (
|
{topup.status === "PENDING" && !topup.is_expired && (
|
||||||
<Button>
|
<Button>
|
||||||
<TextShimmer>Payment Pending</TextShimmer>{" "}
|
<TextShimmer>Payment Pending</TextShimmer>{" "}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!topup.paid &&
|
{!topup.paid &&
|
||||||
(topup.is_expired ? (
|
(topup.is_expired ? (
|
||||||
<Button
|
<Button
|
||||||
disabled
|
disabled
|
||||||
className="rounded-md opacity-100! uppercase font-semibold text-red-500 bg-red-500/20"
|
className="rounded-md opacity-100! uppercase font-semibold text-red-500 bg-red-500/20"
|
||||||
>
|
>
|
||||||
Topup Expired
|
Topup Expired
|
||||||
</Button>
|
</Button>
|
||||||
) : topup.status === "PENDING" ? (
|
) : topup.status === "PENDING" ? (
|
||||||
<CancelTopupButton topupId={topupId} />
|
<CancelTopupButton topupId={topupId} />
|
||||||
) : topup.status === "CANCELLED" ? (
|
) : topup.status === "CANCELLED" ? (
|
||||||
<Button disabled>Topup Cancelled</Button>
|
<Button disabled>Topup Cancelled</Button>
|
||||||
) : (
|
) : (
|
||||||
""
|
""
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{!topup.paid && topup.status === "PENDING" && !topup.is_expired && (
|
{!topup.paid && topup.status === "PENDING" && !topup.is_expired && (
|
||||||
<ExpiryCountDown expiryLabel="Top up" expiresAt={topup.expires_at} />
|
<ExpiryCountDown expiryLabel="Top up" expiresAt={topup.expires_at} />
|
||||||
)}
|
)}
|
||||||
<div
|
<div
|
||||||
id="user-topup-details"
|
id="user-topup-details"
|
||||||
className="pb-4 gap-4 flex sm:flex-row flex-col items-start justify-start"
|
className="pb-4 gap-4 flex sm:flex-row flex-col items-start justify-start"
|
||||||
>
|
>
|
||||||
<TopupToPay
|
<TopupToPay
|
||||||
disabled={
|
disabled={
|
||||||
topup.paid || topup.is_expired || topup.status === "CANCELLED"
|
topup.paid || topup.is_expired || topup.status === "CANCELLED"
|
||||||
}
|
}
|
||||||
topup={topup || undefined}
|
topup={topup || undefined}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,13 @@ import { redirect } from "next/navigation";
|
|||||||
import { getServerSession } from "next-auth";
|
import { getServerSession } from "next-auth";
|
||||||
import { authOptions } from "@/app/auth";
|
import { authOptions } from "@/app/auth";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCaption,
|
TableCell,
|
||||||
TableCell,
|
TableFooter,
|
||||||
TableFooter,
|
TableHead,
|
||||||
TableHead,
|
TableHeader,
|
||||||
TableHeader,
|
TableRow,
|
||||||
TableRow,
|
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { getDevices } from "@/queries/devices";
|
import { getDevices } from "@/queries/devices";
|
||||||
@@ -21,156 +20,155 @@ import ClientErrorMessage from "../client-error-message";
|
|||||||
import Pagination from "../pagination";
|
import Pagination from "../pagination";
|
||||||
|
|
||||||
export async function AdminDevicesTable({
|
export async function AdminDevicesTable({
|
||||||
searchParams,
|
searchParams,
|
||||||
}: {
|
}: {
|
||||||
searchParams: Promise<{
|
searchParams: Promise<{
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
}>;
|
}>;
|
||||||
}) {
|
}) {
|
||||||
const resolvedParams = await searchParams;
|
const resolvedParams = await searchParams;
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
const isAdmin = session?.user?.is_admin;
|
const isAdmin = session?.user?.is_admin;
|
||||||
|
|
||||||
const page = Number.parseInt(resolvedParams.page as string) || 1;
|
const page = Number.parseInt(resolvedParams.page as string) || 1;
|
||||||
const limit = 10;
|
const limit = 10;
|
||||||
const offset = (page - 1) * limit;
|
const offset = (page - 1) * limit;
|
||||||
|
|
||||||
// Build params object for getDevices
|
// Build params object for getDevices
|
||||||
const apiParams: Record<string, string | number | undefined> = {};
|
const apiParams: Record<string, string | number | undefined> = {};
|
||||||
for (const [key, value] of Object.entries(resolvedParams)) {
|
for (const [key, value] of Object.entries(resolvedParams)) {
|
||||||
if (value !== undefined && value !== "") {
|
if (value !== undefined && value !== "") {
|
||||||
apiParams[key] = typeof value === "number" ? value : String(value);
|
apiParams[key] = typeof value === "number" ? value : String(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
apiParams.limit = limit;
|
apiParams.limit = limit;
|
||||||
apiParams.offset = offset;
|
apiParams.offset = offset;
|
||||||
|
|
||||||
const [error, devices] = await tryCatch(getDevices(apiParams, true));
|
const [error, devices] = await tryCatch(getDevices(apiParams, true));
|
||||||
if (error) {
|
if (error) {
|
||||||
if (error.message === "UNAUTHORIZED") {
|
if (error.message === "UNAUTHORIZED") {
|
||||||
redirect("/auth/signin");
|
redirect("/auth/signin");
|
||||||
} else {
|
} else {
|
||||||
return <ClientErrorMessage message={error.message} />;
|
return <ClientErrorMessage message={error.message} />;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const { meta, data } = devices;
|
const { meta, data } = devices;
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{data?.length === 0 ? (
|
{data?.length === 0 ? (
|
||||||
<div className="h-[calc(100svh-400px)] text-muted-foreground flex flex-col items-center justify-center my-4">
|
<div className="h-[calc(100svh-400px)] text-muted-foreground flex flex-col items-center justify-center my-4">
|
||||||
<h3>No devices.</h3>
|
<h3>No devices.</h3>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<div>
|
<div>
|
||||||
<Table className="overflow-scroll">
|
<Table className="overflow-scroll">
|
||||||
<TableCaption>Table of all devices.</TableCaption>
|
<TableHeader>
|
||||||
<TableHeader>
|
<TableRow>
|
||||||
<TableRow>
|
<TableHead>Device Name</TableHead>
|
||||||
<TableHead>Device Name</TableHead>
|
<TableHead>User</TableHead>
|
||||||
<TableHead>User</TableHead>
|
<TableHead>MAC Address</TableHead>
|
||||||
<TableHead>MAC Address</TableHead>
|
<TableHead>Vendor</TableHead>
|
||||||
<TableHead>Vendor</TableHead>
|
<TableHead>#</TableHead>
|
||||||
<TableHead>#</TableHead>
|
</TableRow>
|
||||||
</TableRow>
|
</TableHeader>
|
||||||
</TableHeader>
|
<TableBody className="overflow-scroll">
|
||||||
<TableBody className="overflow-scroll">
|
{data?.map((device) => (
|
||||||
{data?.map((device) => (
|
<TableRow key={device.id}>
|
||||||
<TableRow key={device.id}>
|
<TableCell>
|
||||||
<TableCell>
|
<div className="flex flex-col items-start">
|
||||||
<div className="flex flex-col items-start">
|
<Link
|
||||||
<Link
|
className={cn(
|
||||||
className={cn(
|
"hover:underline font-semibold",
|
||||||
"hover:underline font-semibold",
|
device.is_active ? "text-green-600" : "",
|
||||||
device.is_active ? "text-green-600" : "",
|
)}
|
||||||
)}
|
href={`/devices/${device.id}`}
|
||||||
href={`/devices/${device.id}`}
|
>
|
||||||
>
|
{device.name}
|
||||||
{device.name}
|
</Link>
|
||||||
</Link>
|
{device.is_active ? (
|
||||||
{device.is_active ? (
|
<div className="text-muted-foreground">
|
||||||
<div className="text-muted-foreground">
|
Active until{" "}
|
||||||
Active until{" "}
|
<span className="font-semibold">
|
||||||
<span className="font-semibold">
|
{new Date(
|
||||||
{new Date(
|
device.expiry_date || "",
|
||||||
device.expiry_date || "",
|
).toLocaleDateString("en-US", {
|
||||||
).toLocaleDateString("en-US", {
|
month: "short",
|
||||||
month: "short",
|
day: "2-digit",
|
||||||
day: "2-digit",
|
year: "numeric",
|
||||||
year: "numeric",
|
})}
|
||||||
})}
|
</span>
|
||||||
</span>
|
</div>
|
||||||
</div>
|
) : (
|
||||||
) : (
|
<p className="text-muted-foreground">
|
||||||
<p className="text-muted-foreground">
|
Device Inactive
|
||||||
Device Inactive
|
</p>
|
||||||
</p>
|
)}
|
||||||
)}
|
{device.has_a_pending_payment && (
|
||||||
{device.has_a_pending_payment && (
|
<Link href={`/payments/${device.pending_payment_id}`}>
|
||||||
<Link href={`/payments/${device.pending_payment_id}`}>
|
<span className="bg-muted rounded px-2 p-1 mt-2 flex hover:underline items-center justify-center gap-2 text-muted-foreground">
|
||||||
<span className="bg-muted rounded px-2 p-1 mt-2 flex hover:underline items-center justify-center gap-2 text-muted-foreground">
|
Payment Pending{" "}
|
||||||
Payment Pending{" "}
|
<HandCoins className="animate-pulse" size={14} />
|
||||||
<HandCoins className="animate-pulse" size={14} />
|
</span>
|
||||||
</span>
|
</Link>
|
||||||
</Link>
|
)}
|
||||||
)}
|
|
||||||
|
|
||||||
{device.blocked_by === "ADMIN" && device.blocked && (
|
{device.blocked_by === "ADMIN" && device.blocked && (
|
||||||
<div className="p-2 rounded border my-2 bg-white dark:bg-neutral-800 shadow">
|
<div className="p-2 rounded border my-2 bg-white dark:bg-neutral-800 shadow">
|
||||||
<span className="font-semibold">Comment</span>
|
<span className="font-semibold">Comment</span>
|
||||||
<p className="text-neutral-400">
|
<p className="text-neutral-400">
|
||||||
{device?.reason_for_blocking}
|
{device?.reason_for_blocking}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="font-medium">
|
<TableCell className="font-medium">
|
||||||
<div className="flex flex-col items-start">
|
<div className="flex flex-col items-start">
|
||||||
{device?.user?.name}
|
{device?.user?.name}
|
||||||
<span className="text-muted-foreground">
|
<span className="text-muted-foreground">
|
||||||
{device?.user?.id_card}
|
{device?.user?.id_card}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="font-medium">{device.mac}</TableCell>
|
<TableCell className="font-medium">{device.mac}</TableCell>
|
||||||
<TableCell className="font-medium">
|
<TableCell className="font-medium">
|
||||||
{device?.vendor}
|
{device?.vendor}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{!device.has_a_pending_payment && (
|
{!device.has_a_pending_payment && (
|
||||||
<BlockDeviceDialog
|
<BlockDeviceDialog
|
||||||
admin={isAdmin}
|
admin={isAdmin}
|
||||||
type={device.blocked ? "unblock" : "block"}
|
type={device.blocked ? "unblock" : "block"}
|
||||||
device={device}
|
device={device}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
<TableFooter>
|
<TableFooter>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell colSpan={5} className="text-muted-foreground">
|
<TableCell colSpan={5} className="text-muted-foreground">
|
||||||
{meta?.total === 1 ? (
|
{meta?.total === 1 ? (
|
||||||
<p className="text-center">Total {meta?.total} device.</p>
|
<p className="text-center">Total {meta?.total} device.</p>
|
||||||
) : (
|
) : (
|
||||||
<p className="text-center">
|
<p className="text-center">
|
||||||
Total {meta?.total} devices.
|
Total {meta?.total} devices.
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableFooter>
|
</TableFooter>
|
||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Pagination
|
<Pagination
|
||||||
totalPages={meta?.last_page}
|
totalPages={meta?.last_page}
|
||||||
currentPage={meta?.current_page}
|
currentPage={meta?.current_page}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,13 @@ import Link from "next/link";
|
|||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { getTopups } from "@/actions/payment";
|
import { getTopups } from "@/actions/payment";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCaption,
|
TableCell,
|
||||||
TableCell,
|
TableFooter,
|
||||||
TableFooter,
|
TableHead,
|
||||||
TableHead,
|
TableHeader,
|
||||||
TableHeader,
|
TableRow,
|
||||||
TableRow,
|
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import { tryCatch } from "@/utils/tryCatch";
|
import { tryCatch } from "@/utils/tryCatch";
|
||||||
import Pagination from "../pagination";
|
import Pagination from "../pagination";
|
||||||
@@ -17,123 +16,122 @@ import { Badge } from "../ui/badge";
|
|||||||
import { Button } from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
|
|
||||||
export async function AdminTopupsTable({
|
export async function AdminTopupsTable({
|
||||||
searchParams,
|
searchParams,
|
||||||
}: {
|
}: {
|
||||||
searchParams: Promise<{
|
searchParams: Promise<{
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
}>;
|
}>;
|
||||||
}) {
|
}) {
|
||||||
const resolvedParams = await searchParams;
|
const resolvedParams = await searchParams;
|
||||||
const page = Number.parseInt(resolvedParams.page as string) || 1;
|
const page = Number.parseInt(resolvedParams.page as string) || 1;
|
||||||
const limit = 10;
|
const limit = 10;
|
||||||
const offset = (page - 1) * limit;
|
const offset = (page - 1) * limit;
|
||||||
// Build params object
|
// Build params object
|
||||||
const apiParams: Record<string, string | number | undefined> = {};
|
const apiParams: Record<string, string | number | undefined> = {};
|
||||||
for (const [key, value] of Object.entries(resolvedParams)) {
|
for (const [key, value] of Object.entries(resolvedParams)) {
|
||||||
if (value !== undefined && value !== "") {
|
if (value !== undefined && value !== "") {
|
||||||
apiParams[key] = typeof value === "number" ? value : String(value);
|
apiParams[key] = typeof value === "number" ? value : String(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
apiParams.limit = limit;
|
apiParams.limit = limit;
|
||||||
apiParams.offset = offset;
|
apiParams.offset = offset;
|
||||||
const [error, topups] = await tryCatch(getTopups(apiParams, true));
|
const [error, topups] = await tryCatch(getTopups(apiParams, true));
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
if (error.message.includes("Unauthorized")) {
|
if (error.message.includes("Unauthorized")) {
|
||||||
redirect("/auth/signin");
|
redirect("/auth/signin");
|
||||||
} else {
|
} else {
|
||||||
return <pre>{JSON.stringify(error, null, 2)}</pre>;
|
return <pre>{JSON.stringify(error, null, 2)}</pre>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const { data, meta } = topups;
|
const { data, meta } = topups;
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{data?.length === 0 ? (
|
{data?.length === 0 ? (
|
||||||
<div className="h-[calc(100svh-400px)] flex flex-col items-center justify-center my-4">
|
<div className="h-[calc(100svh-400px)] flex flex-col items-center justify-center my-4">
|
||||||
<h3>No topups yet.</h3>
|
<h3>No topups yet.</h3>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<div>
|
<div>
|
||||||
<Table className="overflow-scroll">
|
<Table className="overflow-scroll">
|
||||||
<TableCaption>Table of all topups.</TableCaption>
|
<TableHeader>
|
||||||
<TableHeader>
|
<TableRow>
|
||||||
<TableRow>
|
<TableHead>User</TableHead>
|
||||||
<TableHead>User</TableHead>
|
<TableHead>Status</TableHead>
|
||||||
<TableHead>Status</TableHead>
|
<TableHead>Amount</TableHead>
|
||||||
<TableHead>Amount</TableHead>
|
<TableHead>Action</TableHead>
|
||||||
<TableHead>Action</TableHead>
|
</TableRow>
|
||||||
</TableRow>
|
</TableHeader>
|
||||||
</TableHeader>
|
<TableBody className="overflow-scroll">
|
||||||
<TableBody className="overflow-scroll">
|
{topups?.data?.map((topup) => (
|
||||||
{topups?.data?.map((topup) => (
|
<TableRow key={topup.id}>
|
||||||
<TableRow key={topup.id}>
|
<TableCell>
|
||||||
<TableCell>
|
<div className="flex flex-col items-start">
|
||||||
<div className="flex flex-col items-start">
|
{topup?.user?.name}
|
||||||
{topup?.user?.name}
|
<span className="text-muted-foreground">
|
||||||
<span className="text-muted-foreground">
|
{topup?.user?.id_card}
|
||||||
{topup?.user?.id_card}
|
</span>
|
||||||
</span>
|
</div>
|
||||||
</div>
|
</TableCell>
|
||||||
</TableCell>
|
<TableCell>
|
||||||
<TableCell>
|
<span className="font-semibold pr-2">
|
||||||
<span className="font-semibold pr-2">
|
{topup.paid ? (
|
||||||
{topup.paid ? (
|
<Badge
|
||||||
<Badge
|
className="bg-green-100 dark:bg-green-700"
|
||||||
className="bg-green-100 dark:bg-green-700"
|
variant="outline"
|
||||||
variant="outline"
|
>
|
||||||
>
|
{topup.status}
|
||||||
{topup.status}
|
</Badge>
|
||||||
</Badge>
|
) : topup.is_expired ? (
|
||||||
) : topup.is_expired ? (
|
<Badge>Expired</Badge>
|
||||||
<Badge>Expired</Badge>
|
) : (
|
||||||
) : (
|
<Badge variant="outline">{topup.status}</Badge>
|
||||||
<Badge variant="outline">{topup.status}</Badge>
|
)}
|
||||||
)}
|
</span>
|
||||||
</span>
|
</TableCell>
|
||||||
</TableCell>
|
<TableCell>
|
||||||
<TableCell>
|
<span className="font-semibold pr-2">
|
||||||
<span className="font-semibold pr-2">
|
{topup.amount.toFixed(2)}
|
||||||
{topup.amount.toFixed(2)}
|
</span>
|
||||||
</span>
|
MVR
|
||||||
MVR
|
</TableCell>
|
||||||
</TableCell>
|
<TableCell>
|
||||||
<TableCell>
|
<div>
|
||||||
<div>
|
<div className="flex items-center gap-2 mt-2">
|
||||||
<div className="flex items-center gap-2 mt-2">
|
<Link
|
||||||
<Link
|
className="font-medium hover:underline"
|
||||||
className="font-medium hover:underline"
|
href={`/top-ups/${topup.id}`}
|
||||||
href={`/top-ups/${topup.id}`}
|
>
|
||||||
>
|
<Button size={"sm"} variant="outline">
|
||||||
<Button size={"sm"} variant="outline">
|
View Details
|
||||||
View Details
|
</Button>
|
||||||
</Button>
|
</Link>
|
||||||
</Link>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</TableCell>
|
||||||
</TableCell>
|
</TableRow>
|
||||||
</TableRow>
|
))}
|
||||||
))}
|
</TableBody>
|
||||||
</TableBody>
|
<TableFooter>
|
||||||
<TableFooter>
|
<TableRow>
|
||||||
<TableRow>
|
<TableCell colSpan={4} className="text-muted-foreground">
|
||||||
<TableCell colSpan={4} className="text-muted-foreground">
|
{meta?.total === 1 ? (
|
||||||
{meta?.total === 1 ? (
|
<p className="text-center">Total {meta?.total} topup.</p>
|
||||||
<p className="text-center">Total {meta?.total} topup.</p>
|
) : (
|
||||||
) : (
|
<p className="text-center">Total {meta?.total} topups.</p>
|
||||||
<p className="text-center">Total {meta?.total} topups.</p>
|
)}
|
||||||
)}
|
</TableCell>
|
||||||
</TableCell>
|
</TableRow>
|
||||||
</TableRow>
|
</TableFooter>
|
||||||
</TableFooter>
|
</Table>
|
||||||
</Table>
|
</div>
|
||||||
</div>
|
<Pagination
|
||||||
<Pagination
|
totalPages={meta?.last_page}
|
||||||
totalPages={meta?.last_page}
|
currentPage={meta?.current_page}
|
||||||
currentPage={meta?.current_page}
|
/>
|
||||||
/>
|
</>
|
||||||
</>
|
)}
|
||||||
)}
|
</div>
|
||||||
</div>
|
);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,170 +5,168 @@ import Pagination from "@/components/pagination";
|
|||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCaption,
|
TableCell,
|
||||||
TableCell,
|
TableFooter,
|
||||||
TableFooter,
|
TableHead,
|
||||||
TableHead,
|
TableHeader,
|
||||||
TableHeader,
|
TableRow,
|
||||||
TableRow,
|
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import { tryCatch } from "@/utils/tryCatch";
|
import { tryCatch } from "@/utils/tryCatch";
|
||||||
import ClientErrorMessage from "../client-error-message";
|
import ClientErrorMessage from "../client-error-message";
|
||||||
|
|
||||||
export async function UsersPaymentsTable({
|
export async function UsersPaymentsTable({
|
||||||
searchParams,
|
searchParams,
|
||||||
}: {
|
}: {
|
||||||
searchParams: Promise<{
|
searchParams: Promise<{
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
}>;
|
}>;
|
||||||
}) {
|
}) {
|
||||||
const resolvedParams = await searchParams;
|
const resolvedParams = await searchParams;
|
||||||
|
|
||||||
const page = Number.parseInt(resolvedParams.page as string) || 1;
|
const page = Number.parseInt(resolvedParams.page as string) || 1;
|
||||||
const limit = 10;
|
const limit = 10;
|
||||||
const offset = (page - 1) * limit;
|
const offset = (page - 1) * limit;
|
||||||
|
|
||||||
// Build params object for getDevices
|
// Build params object for getDevices
|
||||||
const apiParams: Record<string, string | number | undefined> = {};
|
const apiParams: Record<string, string | number | undefined> = {};
|
||||||
for (const [key, value] of Object.entries(resolvedParams)) {
|
for (const [key, value] of Object.entries(resolvedParams)) {
|
||||||
if (value !== undefined && value !== "") {
|
if (value !== undefined && value !== "") {
|
||||||
apiParams[key] = typeof value === "number" ? value : String(value);
|
apiParams[key] = typeof value === "number" ? value : String(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
apiParams.limit = limit;
|
apiParams.limit = limit;
|
||||||
apiParams.offset = offset;
|
apiParams.offset = offset;
|
||||||
|
|
||||||
const [error, payments] = await tryCatch(getPayments(apiParams, true));
|
const [error, payments] = await tryCatch(getPayments(apiParams, true));
|
||||||
if (error) {
|
if (error) {
|
||||||
if (error.message === "UNAUTHORIZED") {
|
if (error.message === "UNAUTHORIZED") {
|
||||||
redirect("/auth/signin");
|
redirect("/auth/signin");
|
||||||
} else {
|
} else {
|
||||||
return <ClientErrorMessage message={error.message} />;
|
return <ClientErrorMessage message={error.message} />;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const { meta, data } = payments;
|
const { meta, data } = payments;
|
||||||
|
|
||||||
// return <pre>{JSON.stringify(payments, null, 2)}</pre>;
|
// return <pre>{JSON.stringify(payments, null, 2)}</pre>;
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{data.length === 0 ? (
|
{data.length === 0 ? (
|
||||||
<div className="h-[calc(100svh-400px)] flex flex-col items-center justify-center my-4">
|
<div className="h-[calc(100svh-400px)] flex flex-col items-center justify-center my-4">
|
||||||
<h3>No user payments yet.</h3>
|
<h3>No user payments yet.</h3>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<Table className="overflow-scroll">
|
<Table className="overflow-scroll">
|
||||||
<TableCaption>Table of all users.</TableCaption>
|
<TableHeader>
|
||||||
<TableHeader>
|
<TableRow>
|
||||||
<TableRow>
|
<TableHead>Devices paid</TableHead>
|
||||||
<TableHead>Devices paid</TableHead>
|
<TableHead>User</TableHead>
|
||||||
<TableHead>User</TableHead>
|
<TableHead>Amount</TableHead>
|
||||||
<TableHead>Amount</TableHead>
|
<TableHead>Duration</TableHead>
|
||||||
<TableHead>Duration</TableHead>
|
<TableHead>Payment Status</TableHead>
|
||||||
<TableHead>Payment Status</TableHead>
|
<TableHead>Payment Method</TableHead>
|
||||||
<TableHead>Payment Method</TableHead>
|
<TableHead>MIB Reference</TableHead>
|
||||||
<TableHead>MIB Reference</TableHead>
|
<TableHead>Paid At</TableHead>
|
||||||
<TableHead>Paid At</TableHead>
|
<TableHead>Action</TableHead>
|
||||||
<TableHead>Action</TableHead>
|
</TableRow>
|
||||||
</TableRow>
|
</TableHeader>
|
||||||
</TableHeader>
|
<TableBody className="overflow-scroll">
|
||||||
<TableBody className="overflow-scroll">
|
{data.map((payment) => (
|
||||||
{data.map((payment) => (
|
<TableRow
|
||||||
<TableRow
|
className={`${payment.paid && "title-bg dark:bg-black"}`}
|
||||||
className={`${payment.paid && "title-bg dark:bg-black"}`}
|
key={payment.id}
|
||||||
key={payment.id}
|
>
|
||||||
>
|
<TableCell className="font-medium">
|
||||||
<TableCell className="font-medium">
|
<ol className="list-disc list-inside text-sm">
|
||||||
<ol className="list-disc list-inside text-sm">
|
{payment.devices.map((device) => (
|
||||||
{payment.devices.map((device) => (
|
<li
|
||||||
<li
|
key={device.id}
|
||||||
key={device.id}
|
className="text-sm text-muted-foreground"
|
||||||
className="text-sm text-muted-foreground"
|
>
|
||||||
>
|
{device.name}
|
||||||
{device.name}
|
</li>
|
||||||
</li>
|
))}
|
||||||
))}
|
</ol>
|
||||||
</ol>
|
</TableCell>
|
||||||
</TableCell>
|
<TableCell className="font-medium">
|
||||||
<TableCell className="font-medium">
|
{/* {payment.user.id_card} */}
|
||||||
{/* {payment.user.id_card} */}
|
<div className="flex flex-col items-start">
|
||||||
<div className="flex flex-col items-start">
|
{payment?.user?.name}
|
||||||
{payment?.user?.name}
|
<span className="text-muted-foreground">
|
||||||
<span className="text-muted-foreground">
|
{payment?.user?.id_card}
|
||||||
{payment?.user?.id_card}
|
</span>
|
||||||
</span>
|
</div>{" "}
|
||||||
</div>{" "}
|
</TableCell>
|
||||||
</TableCell>
|
<TableCell>{payment.amount} MVR</TableCell>
|
||||||
<TableCell>{payment.amount} MVR</TableCell>
|
<TableCell>{payment.number_of_months} Months</TableCell>
|
||||||
<TableCell>{payment.number_of_months} Months</TableCell>
|
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{payment.status === "PENDING" ? (
|
{payment.status === "PENDING" ? (
|
||||||
<Badge
|
<Badge
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="bg-yellow-100 text-black"
|
className="bg-yellow-100 text-black"
|
||||||
>
|
>
|
||||||
{payment.status}
|
{payment.status}
|
||||||
</Badge>
|
</Badge>
|
||||||
) : payment.status === "PAID" ? (
|
) : payment.status === "PAID" ? (
|
||||||
<Badge
|
<Badge
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="bg-lime-100 text-black"
|
className="bg-lime-100 text-black"
|
||||||
>
|
>
|
||||||
{payment.status}
|
{payment.status}
|
||||||
</Badge>
|
</Badge>
|
||||||
) : (
|
) : (
|
||||||
<Badge
|
<Badge
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="bg-red-100 text-black"
|
className="bg-red-100 text-black"
|
||||||
>
|
>
|
||||||
{payment.status}
|
{payment.status}
|
||||||
</Badge>
|
</Badge>
|
||||||
)}
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>{payment.method}</TableCell>
|
<TableCell>{payment.method}</TableCell>
|
||||||
<TableCell>{payment.mib_reference}</TableCell>
|
<TableCell>{payment.mib_reference}</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{new Date(payment.paid_at ?? "").toLocaleDateString(
|
{new Date(payment.paid_at ?? "").toLocaleDateString(
|
||||||
"en-US",
|
"en-US",
|
||||||
{
|
{
|
||||||
month: "short",
|
month: "short",
|
||||||
day: "2-digit",
|
day: "2-digit",
|
||||||
year: "numeric",
|
year: "numeric",
|
||||||
minute: "2-digit",
|
minute: "2-digit",
|
||||||
hour: "2-digit",
|
hour: "2-digit",
|
||||||
},
|
},
|
||||||
)}
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Link href={`/payments/${payment.id}`}>
|
<Link href={`/payments/${payment.id}`}>
|
||||||
<Button>Details</Button>
|
<Button>Details</Button>
|
||||||
</Link>
|
</Link>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
<TableFooter>
|
<TableFooter>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell colSpan={10} className="text-muted-foreground">
|
<TableCell colSpan={10} className="text-muted-foreground">
|
||||||
{meta?.total === 1 ? (
|
{meta?.total === 1 ? (
|
||||||
<p className="text-center">Total {meta?.total} payment.</p>
|
<p className="text-center">Total {meta?.total} payment.</p>
|
||||||
) : (
|
) : (
|
||||||
<p className="text-center">Total {meta?.total} payments.</p>
|
<p className="text-center">Total {meta?.total} payments.</p>
|
||||||
)}{" "}
|
)}{" "}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableFooter>
|
</TableFooter>
|
||||||
</Table>
|
</Table>
|
||||||
<Pagination
|
<Pagination
|
||||||
totalPages={meta?.last_page}
|
totalPages={meta?.last_page}
|
||||||
currentPage={meta?.current_page}
|
currentPage={meta?.current_page}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,13 @@ import { redirect } from "next/navigation";
|
|||||||
import { getServerSession } from "next-auth";
|
import { getServerSession } from "next-auth";
|
||||||
import { authOptions } from "@/app/auth";
|
import { authOptions } from "@/app/auth";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCaption,
|
TableCell,
|
||||||
TableCell,
|
TableFooter,
|
||||||
TableFooter,
|
TableHead,
|
||||||
TableHead,
|
TableHeader,
|
||||||
TableHeader,
|
TableRow,
|
||||||
TableRow,
|
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import { getDevices } from "@/queries/devices";
|
import { getDevices } from "@/queries/devices";
|
||||||
import { tryCatch } from "@/utils/tryCatch";
|
import { tryCatch } from "@/utils/tryCatch";
|
||||||
@@ -19,107 +18,106 @@ import DeviceCard from "./device-card";
|
|||||||
import Pagination from "./pagination";
|
import Pagination from "./pagination";
|
||||||
|
|
||||||
export async function DevicesTable({
|
export async function DevicesTable({
|
||||||
searchParams,
|
searchParams,
|
||||||
parentalControl,
|
parentalControl,
|
||||||
additionalFilters = {},
|
additionalFilters = {},
|
||||||
}: {
|
}: {
|
||||||
searchParams: Promise<{
|
searchParams: Promise<{
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
}>;
|
}>;
|
||||||
parentalControl?: boolean;
|
parentalControl?: boolean;
|
||||||
additionalFilters?: Record<string, string | number | boolean>;
|
additionalFilters?: Record<string, string | number | boolean>;
|
||||||
}) {
|
}) {
|
||||||
const resolvedParams = await searchParams;
|
const resolvedParams = await searchParams;
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
const isAdmin = session?.user?.is_admin;
|
const isAdmin = session?.user?.is_admin;
|
||||||
|
|
||||||
const page = Number.parseInt(resolvedParams.page as string) || 1;
|
const page = Number.parseInt(resolvedParams.page as string) || 1;
|
||||||
const limit = 10;
|
const limit = 10;
|
||||||
const offset = (page - 1) * limit;
|
const offset = (page - 1) * limit;
|
||||||
|
|
||||||
// Build params object for getDevices
|
// Build params object for getDevices
|
||||||
const apiParams: Record<string, string | number | undefined> = {};
|
const apiParams: Record<string, string | number | undefined> = {};
|
||||||
for (const [key, value] of Object.entries(resolvedParams)) {
|
for (const [key, value] of Object.entries(resolvedParams)) {
|
||||||
if (value !== undefined && value !== "") {
|
if (value !== undefined && value !== "") {
|
||||||
apiParams[key] = typeof value === "number" ? value : String(value);
|
apiParams[key] = typeof value === "number" ? value : String(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(additionalFilters)) {
|
for (const [key, value] of Object.entries(additionalFilters)) {
|
||||||
if (value !== undefined && value !== "") {
|
if (value !== undefined && value !== "") {
|
||||||
apiParams[key] = typeof value === "number" ? value : String(value);
|
apiParams[key] = typeof value === "number" ? value : String(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
apiParams.limit = limit;
|
apiParams.limit = limit;
|
||||||
apiParams.offset = offset;
|
apiParams.offset = offset;
|
||||||
const [error, devices] = await tryCatch(getDevices(apiParams));
|
const [error, devices] = await tryCatch(getDevices(apiParams));
|
||||||
if (error) {
|
if (error) {
|
||||||
if (error.message === "UNAUTHORIZED") {
|
if (error.message === "UNAUTHORIZED") {
|
||||||
redirect("/auth/signin");
|
redirect("/auth/signin");
|
||||||
} else {
|
} else {
|
||||||
return <ClientErrorMessage message={error.message} />;
|
return <ClientErrorMessage message={error.message} />;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const { meta, data } = devices;
|
const { meta, data } = devices;
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{data?.length === 0 ? (
|
{data?.length === 0 ? (
|
||||||
<div className="h-[calc(100svh-400px)] text-muted-foreground flex flex-col items-center justify-center my-4">
|
<div className="h-[calc(100svh-400px)] text-muted-foreground flex flex-col items-center justify-center my-4">
|
||||||
<h3>{parentalControl ? "No active devices" : "No devices."}</h3>
|
<h3>{parentalControl ? "No active devices" : "No devices."}</h3>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<div className="hidden sm:block">
|
<div className="hidden sm:block">
|
||||||
<Table className="overflow-scroll">
|
<Table className="overflow-scroll">
|
||||||
<TableCaption>Table of all devices.</TableCaption>
|
<TableHeader>
|
||||||
<TableHeader>
|
<TableRow>
|
||||||
<TableRow>
|
<TableHead>Device Name</TableHead>
|
||||||
<TableHead>Device Name</TableHead>
|
<TableHead>MAC Address</TableHead>
|
||||||
<TableHead>MAC Address</TableHead>
|
<TableHead>Vendor</TableHead>
|
||||||
<TableHead>Vendor</TableHead>
|
<TableHead>#</TableHead>
|
||||||
<TableHead>#</TableHead>
|
</TableRow>
|
||||||
</TableRow>
|
</TableHeader>
|
||||||
</TableHeader>
|
<TableBody className="overflow-scroll">
|
||||||
<TableBody className="overflow-scroll">
|
{data?.map((device) => (
|
||||||
{data?.map((device) => (
|
<ClickableRow
|
||||||
<ClickableRow
|
admin={isAdmin}
|
||||||
admin={isAdmin}
|
key={device.id}
|
||||||
key={device.id}
|
device={device}
|
||||||
device={device}
|
parentalControl={parentalControl}
|
||||||
parentalControl={parentalControl}
|
/>
|
||||||
/>
|
))}
|
||||||
))}
|
</TableBody>
|
||||||
</TableBody>
|
<TableFooter>
|
||||||
<TableFooter>
|
<TableRow>
|
||||||
<TableRow>
|
<TableCell colSpan={4} className="text-muted-foreground">
|
||||||
<TableCell colSpan={4} className="text-muted-foreground">
|
{meta?.total === 1 ? (
|
||||||
{meta?.total === 1 ? (
|
<p className="text-center">Total {meta?.total} device.</p>
|
||||||
<p className="text-center">Total {meta?.total} device.</p>
|
) : (
|
||||||
) : (
|
<p className="text-center">
|
||||||
<p className="text-center">
|
Total {meta?.total} devices.
|
||||||
Total {meta?.total} devices.
|
</p>
|
||||||
</p>
|
)}
|
||||||
)}
|
</TableCell>
|
||||||
</TableCell>
|
</TableRow>
|
||||||
</TableRow>
|
</TableFooter>
|
||||||
</TableFooter>
|
</Table>
|
||||||
</Table>
|
</div>
|
||||||
</div>
|
<div className="sm:hidden my-4">
|
||||||
<div className="sm:hidden my-4">
|
{data?.map((device) => (
|
||||||
{data?.map((device) => (
|
<DeviceCard
|
||||||
<DeviceCard
|
parentalControl={parentalControl}
|
||||||
parentalControl={parentalControl}
|
key={device.id}
|
||||||
key={device.id}
|
device={device}
|
||||||
device={device}
|
/>
|
||||||
/>
|
))}
|
||||||
))}
|
</div>
|
||||||
</div>
|
<Pagination
|
||||||
<Pagination
|
totalPages={meta?.last_page}
|
||||||
totalPages={meta?.last_page}
|
currentPage={meta?.current_page}
|
||||||
currentPage={meta?.current_page}
|
/>
|
||||||
/>
|
</>
|
||||||
</>
|
)}
|
||||||
)}
|
</div>
|
||||||
</div>
|
);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,62 +1,63 @@
|
|||||||
import { cn } from "@/lib/utils";
|
|
||||||
import { Minus, Plus } from "lucide-react";
|
import { Minus, Plus } from "lucide-react";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Group,
|
Group,
|
||||||
Input,
|
Input,
|
||||||
Label,
|
Label,
|
||||||
NumberField,
|
NumberField,
|
||||||
} from "react-aria-components";
|
} from "react-aria-components";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
export default function NumberInput({
|
export default function NumberInput({
|
||||||
maxAllowed,
|
maxAllowed,
|
||||||
label,
|
label,
|
||||||
value,
|
value = 100,
|
||||||
onChange,
|
onChange,
|
||||||
className,
|
className,
|
||||||
isDisabled,
|
isDisabled,
|
||||||
}: {
|
}: {
|
||||||
maxAllowed?: number;
|
maxAllowed?: number;
|
||||||
label: string;
|
label: string;
|
||||||
value: number;
|
value?: number;
|
||||||
onChange: (value: number) => void;
|
onChange: (value: number) => void;
|
||||||
className?: string;
|
className?: string;
|
||||||
isDisabled?: boolean;
|
isDisabled?: boolean;
|
||||||
}) {
|
}) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (maxAllowed) {
|
if (maxAllowed) {
|
||||||
if (value > maxAllowed) {
|
if (value > maxAllowed) {
|
||||||
onChange(maxAllowed);
|
onChange(maxAllowed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [maxAllowed, value, onChange]);
|
}, [maxAllowed, value, onChange]);
|
||||||
return (
|
|
||||||
<NumberField
|
return (
|
||||||
isDisabled={isDisabled}
|
<NumberField
|
||||||
className={cn(className)}
|
isDisabled={isDisabled}
|
||||||
value={value}
|
className={cn(className)}
|
||||||
minValue={0}
|
value={value}
|
||||||
onChange={onChange}
|
minValue={0}
|
||||||
>
|
onChange={onChange}
|
||||||
<div className="space-y-2">
|
>
|
||||||
<Label className="text-sm font-medium text-foreground">{label}</Label>
|
<div className="space-y-2">
|
||||||
<Group className="relative inline-flex h-9 w-full items-center overflow-hidden whitespace-nowrap rounded-lg border border-input text-sm shadow-sm shadow-black/5 transition-shadow data-[focus-within]:border-ring data-disabled:opacity-50 data-focus-within:outline-none data-focus-within:ring-[3px] data-[focus-within]:ring-ring/20">
|
<Label className="text-sm font-medium text-foreground">{label}</Label>
|
||||||
<Button
|
<Group className="relative inline-flex h-9 w-full items-center overflow-hidden whitespace-nowrap rounded-lg border border-input text-sm shadow-sm shadow-black/5 transition-shadow data-[focus-within]:border-ring data-disabled:opacity-50 data-focus-within:outline-none data-focus-within:ring-[3px] data-[focus-within]:ring-ring/20">
|
||||||
slot="decrement"
|
<Button
|
||||||
className="-ms-px flex aspect-square h-[inherit] items-center justify-center rounded-s-lg border border-input bg-background text-sm text-muted-foreground/80 transition-shadow hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
|
slot="decrement"
|
||||||
>
|
className="-ms-px flex aspect-square h-[inherit] items-center justify-center rounded-s-lg border border-input bg-background text-sm text-muted-foreground/80 transition-shadow hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
<Minus size={16} strokeWidth={2} aria-hidden="true" />
|
>
|
||||||
</Button>
|
<Minus size={16} strokeWidth={2} aria-hidden="true" />
|
||||||
<Input className="w-full grow bg-background px-3 py-2 text-center text-base tabular-nums text-foreground focus:outline-none" />
|
</Button>
|
||||||
<Button
|
<Input className="w-full grow bg-background px-3 py-2 text-center text-base tabular-nums text-foreground focus:outline-none" />
|
||||||
slot="increment"
|
<Button
|
||||||
className="-me-px flex aspect-square h-[inherit] items-center justify-center rounded-e-lg border border-input bg-background text-sm text-muted-foreground/80 transition-shadow hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
|
slot="increment"
|
||||||
>
|
className="-me-px flex aspect-square h-[inherit] items-center justify-center rounded-e-lg border border-input bg-background text-sm text-muted-foreground/80 transition-shadow hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
<Plus size={16} strokeWidth={2} aria-hidden="true" />
|
>
|
||||||
</Button>
|
<Plus size={16} strokeWidth={2} aria-hidden="true" />
|
||||||
</Group>
|
</Button>
|
||||||
</div>
|
</Group>
|
||||||
</NumberField>
|
</div>
|
||||||
);
|
</NumberField>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,109 +1,113 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import { ArrowLeftIcon, ArrowRightIcon } from "lucide-react";
|
import { ArrowLeftIcon, ArrowRightIcon } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter, useSearchParams } from "next/navigation";
|
import { useRouter, useSearchParams } from "next/navigation";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
|
||||||
type PaginationProps = {
|
type PaginationProps = {
|
||||||
totalPages: number;
|
totalPages: number;
|
||||||
currentPage: number;
|
currentPage: number;
|
||||||
maxVisible?: number;
|
maxVisible?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Pagination({
|
export default function Pagination({
|
||||||
totalPages,
|
totalPages,
|
||||||
currentPage,
|
currentPage,
|
||||||
maxVisible = 4,
|
maxVisible = 4,
|
||||||
}: PaginationProps) {
|
}: PaginationProps) {
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const activePage = searchParams.get("page") ?? 1;
|
const activePage = searchParams.get("page") ?? 1;
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const [queryParams, setQueryParams] = useState<{ [key: string]: string }>({});
|
const [queryParams, setQueryParams] = useState<{ [key: string]: string }>({});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const params = Object.fromEntries(
|
const params = Object.fromEntries(
|
||||||
Array.from(searchParams.entries()).filter(([key]) => key !== "page"),
|
Array.from(searchParams.entries()).filter(([key]) => key !== "page"),
|
||||||
);
|
);
|
||||||
setQueryParams(params);
|
setQueryParams(params);
|
||||||
}, [searchParams]);
|
}, [searchParams]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!searchParams.has("page")) {
|
if (!searchParams.has("page")) {
|
||||||
router.replace(`?page=1${IncludeQueries()}`);
|
router.replace(`?page=1${IncludeQueries()}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function IncludeQueries() {
|
function IncludeQueries() {
|
||||||
return Object.entries(queryParams)
|
return Object.entries(queryParams)
|
||||||
.map(([key, value]) => `&${key}=${value}`)
|
.map(([key, value]) => `&${key}=${value}`)
|
||||||
.join("");
|
.join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
const generatePageNumbers = (): (number | string)[] => {
|
const generatePageNumbers = (): (number | string)[] => {
|
||||||
const halfVisible = Math.floor(maxVisible / 2);
|
const halfVisible = Math.floor(maxVisible / 2);
|
||||||
let startPage = Math.max(currentPage - halfVisible, 1);
|
let startPage = Math.max(currentPage - halfVisible, 1);
|
||||||
const endPage = Math.min(startPage + maxVisible - 1, totalPages);
|
const endPage = Math.min(startPage + maxVisible - 1, totalPages);
|
||||||
|
|
||||||
if (endPage - startPage + 1 < maxVisible) {
|
if (endPage - startPage + 1 < maxVisible) {
|
||||||
startPage = Math.max(endPage - maxVisible + 1, 1);
|
startPage = Math.max(endPage - maxVisible + 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const pageNumbers: (number | string)[] = [];
|
const pageNumbers: (number | string)[] = [];
|
||||||
|
|
||||||
if (startPage > 1) {
|
if (startPage > 1) {
|
||||||
pageNumbers.push(1);
|
pageNumbers.push(1);
|
||||||
if (startPage > 2) pageNumbers.push("...");
|
if (startPage > 2) pageNumbers.push("...");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = startPage; i <= endPage; i++) {
|
for (let i = startPage; i <= endPage; i++) {
|
||||||
pageNumbers.push(i);
|
pageNumbers.push(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endPage < totalPages) {
|
if (endPage < totalPages) {
|
||||||
if (endPage < totalPages - 1) pageNumbers.push("...");
|
if (endPage < totalPages - 1) pageNumbers.push("...");
|
||||||
pageNumbers.push(totalPages);
|
pageNumbers.push(totalPages);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pageNumbers;
|
return pageNumbers;
|
||||||
};
|
};
|
||||||
|
|
||||||
const pageNumbers = generatePageNumbers();
|
const pageNumbers = generatePageNumbers();
|
||||||
|
|
||||||
return (
|
if (totalPages <= 1) {
|
||||||
<div className="flex items-center justify-center space-x-2 my-4">
|
return null;
|
||||||
{currentPage > 1 && (
|
}
|
||||||
<Link href={`?page=${Number(currentPage) - 1}${IncludeQueries()}`}>
|
|
||||||
<Button variant="secondary" className="flex items-center gap-2">
|
|
||||||
<ArrowLeftIcon className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</Link>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{pageNumbers.map((page) => (
|
return (
|
||||||
<React.Fragment key={`${page}`}>
|
<div className="flex items-center justify-center space-x-2 my-4">
|
||||||
{typeof page === "number" ? (
|
{currentPage > 1 && (
|
||||||
<Link href={`?page=${page}${IncludeQueries()}`}>
|
<Link href={`?page=${Number(currentPage) - 1}${IncludeQueries()}`}>
|
||||||
<Button
|
<Button variant="secondary" className="flex items-center gap-2">
|
||||||
variant={Number(activePage) === page ? "default" : "outline"}
|
<ArrowLeftIcon className="h-4 w-4" />
|
||||||
>
|
</Button>
|
||||||
{page}
|
</Link>
|
||||||
</Button>
|
)}
|
||||||
</Link>
|
|
||||||
) : (
|
|
||||||
<span className="px-2">...</span>
|
|
||||||
)}
|
|
||||||
</React.Fragment>
|
|
||||||
))}
|
|
||||||
|
|
||||||
{currentPage < totalPages && (
|
{pageNumbers.map((page) => (
|
||||||
<Link href={`?page=${Number(currentPage) + 1}${IncludeQueries()}`}>
|
<React.Fragment key={`${page}`}>
|
||||||
<Button variant="secondary" className="flex items-center gap-2">
|
{typeof page === "number" ? (
|
||||||
<ArrowRightIcon className="h-4 w-4" />
|
<Link href={`?page=${page}${IncludeQueries()}`}>
|
||||||
</Button>
|
<Button
|
||||||
</Link>
|
variant={Number(activePage) === page ? "default" : "outline"}
|
||||||
)}
|
>
|
||||||
</div>
|
{page}
|
||||||
);
|
</Button>
|
||||||
|
</Link>
|
||||||
|
) : (
|
||||||
|
<span className="px-2">...</span>
|
||||||
|
)}
|
||||||
|
</React.Fragment>
|
||||||
|
))}
|
||||||
|
|
||||||
|
{currentPage < totalPages && (
|
||||||
|
<Link href={`?page=${Number(currentPage) + 1}${IncludeQueries()}`}>
|
||||||
|
<Button variant="secondary" className="flex items-center gap-2">
|
||||||
|
<ArrowRightIcon className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,13 @@ import Link from "next/link";
|
|||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { getPayments } from "@/actions/payment";
|
import { getPayments } from "@/actions/payment";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCaption,
|
TableCell,
|
||||||
TableCell,
|
TableFooter,
|
||||||
TableFooter,
|
TableHead,
|
||||||
TableHead,
|
TableHeader,
|
||||||
TableHeader,
|
TableRow,
|
||||||
TableRow,
|
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import type { Payment } from "@/lib/backend-types";
|
import type { Payment } from "@/lib/backend-types";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
@@ -21,266 +20,265 @@ import { Button } from "./ui/button";
|
|||||||
import { Separator } from "./ui/separator";
|
import { Separator } from "./ui/separator";
|
||||||
|
|
||||||
export async function PaymentsTable({
|
export async function PaymentsTable({
|
||||||
searchParams,
|
searchParams,
|
||||||
}: {
|
}: {
|
||||||
searchParams: Promise<{
|
searchParams: Promise<{
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
}>;
|
}>;
|
||||||
}) {
|
}) {
|
||||||
const resolvedParams = await searchParams;
|
const resolvedParams = await searchParams;
|
||||||
const page = Number.parseInt(resolvedParams.page as string) || 1;
|
const page = Number.parseInt(resolvedParams.page as string) || 1;
|
||||||
const limit = 10;
|
const limit = 10;
|
||||||
const offset = (page - 1) * limit;
|
const offset = (page - 1) * limit;
|
||||||
const apiParams: Record<string, string | number | undefined> = {};
|
const apiParams: Record<string, string | number | undefined> = {};
|
||||||
for (const [key, value] of Object.entries(resolvedParams)) {
|
for (const [key, value] of Object.entries(resolvedParams)) {
|
||||||
if (value !== undefined && value !== "") {
|
if (value !== undefined && value !== "") {
|
||||||
apiParams[key] = typeof value === "number" ? value : String(value);
|
apiParams[key] = typeof value === "number" ? value : String(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
apiParams.limit = limit;
|
apiParams.limit = limit;
|
||||||
apiParams.offset = offset;
|
apiParams.offset = offset;
|
||||||
const [error, payments] = await tryCatch(getPayments(apiParams));
|
const [error, payments] = await tryCatch(getPayments(apiParams));
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
if (error.message.includes("Unauthorized")) {
|
if (error.message.includes("Unauthorized")) {
|
||||||
redirect("/auth/signin");
|
redirect("/auth/signin");
|
||||||
} else {
|
} else {
|
||||||
return <pre>{JSON.stringify(error, null, 2)}</pre>;
|
return <pre>{JSON.stringify(error, null, 2)}</pre>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const { data, meta } = payments;
|
const { data, meta } = payments;
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{data?.length === 0 ? (
|
{data?.length === 0 ? (
|
||||||
<div className="h-[calc(100svh-400px)] text-muted-foreground flex flex-col items-center justify-center my-4">
|
<div className="h-[calc(100svh-400px)] text-muted-foreground flex flex-col items-center justify-center my-4">
|
||||||
<h3>No Payments.</h3>
|
<h3>No Payments.</h3>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<div className="hidden sm:block">
|
<div className="hidden sm:block">
|
||||||
<Table className="overflow-scroll">
|
<Table className="overflow-scroll">
|
||||||
<TableCaption>Table of all devices.</TableCaption>
|
<TableHeader>
|
||||||
<TableHeader>
|
<TableRow>
|
||||||
<TableRow>
|
<TableHead>Details</TableHead>
|
||||||
<TableHead>Details</TableHead>
|
<TableHead>Duration</TableHead>
|
||||||
<TableHead>Duration</TableHead>
|
<TableHead>Status</TableHead>
|
||||||
<TableHead>Status</TableHead>
|
<TableHead>Amount</TableHead>
|
||||||
<TableHead>Amount</TableHead>
|
</TableRow>
|
||||||
</TableRow>
|
</TableHeader>
|
||||||
</TableHeader>
|
<TableBody className="overflow-scroll">
|
||||||
<TableBody className="overflow-scroll">
|
{payments?.data?.map((payment) => (
|
||||||
{payments?.data?.map((payment) => (
|
<TableRow key={payment.id}>
|
||||||
<TableRow key={payment.id}>
|
<TableCell>
|
||||||
<TableCell>
|
<div
|
||||||
<div
|
className={cn(
|
||||||
className={cn(
|
"flex flex-col items-start border rounded p-2",
|
||||||
"flex flex-col items-start border rounded p-2",
|
payment?.paid
|
||||||
payment?.paid
|
? "bg-green-500/10 border-dashed border-green-500"
|
||||||
? "bg-green-500/10 border-dashed border-green-500"
|
: payment?.is_expired
|
||||||
: payment?.is_expired
|
? "bg-gray-500/10 border-dashed border-gray-500 dark:border-gray-500/50"
|
||||||
? "bg-gray-500/10 border-dashed border-gray-500 dark:border-gray-500/50"
|
: "bg-yellow-500/10 border-dashed border-yellow-500 dark:border-yellow-500/50",
|
||||||
: "bg-yellow-500/10 border-dashed border-yellow-500 dark:border-yellow-500/50",
|
)}
|
||||||
)}
|
>
|
||||||
>
|
<div className="flex items-center gap-2">
|
||||||
<div className="flex items-center gap-2">
|
<Calendar size={16} opacity={0.5} />
|
||||||
<Calendar size={16} opacity={0.5} />
|
<span className="text-muted-foreground">
|
||||||
<span className="text-muted-foreground">
|
{new Date(payment.created_at).toLocaleDateString(
|
||||||
{new Date(payment.created_at).toLocaleDateString(
|
"en-US",
|
||||||
"en-US",
|
{
|
||||||
{
|
month: "short",
|
||||||
month: "short",
|
day: "2-digit",
|
||||||
day: "2-digit",
|
year: "numeric",
|
||||||
year: "numeric",
|
minute: "2-digit",
|
||||||
minute: "2-digit",
|
hour: "2-digit",
|
||||||
hour: "2-digit",
|
timeZone: "Indian/Maldives", // Force consistent timezone
|
||||||
timeZone: "Indian/Maldives", // Force consistent timezone
|
},
|
||||||
},
|
)}
|
||||||
)}
|
</span>
|
||||||
</span>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex items-center gap-2 mt-2">
|
<div className="flex items-center gap-2 mt-2">
|
||||||
<Link
|
<Link
|
||||||
className="font-medium hover:underline"
|
className="font-medium hover:underline"
|
||||||
href={`/payments/${payment.id}`}
|
href={`/payments/${payment.id}`}
|
||||||
>
|
>
|
||||||
<Button size={"sm"} variant="outline">
|
<Button size={"sm"} variant="outline">
|
||||||
View Details
|
View Details
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
<div className="bg-white dark:bg-black p-2 rounded mt-2 w-full border">
|
<div className="bg-white dark:bg-black p-2 rounded mt-2 w-full border">
|
||||||
<h3 className="text-sm font-medium">Devices</h3>
|
<h3 className="text-sm font-medium">Devices</h3>
|
||||||
<ol className="list-disc list-inside text-sm">
|
<ol className="list-disc list-inside text-sm">
|
||||||
{payment.devices.map((device) => (
|
{payment.devices.map((device) => (
|
||||||
<li
|
<li
|
||||||
key={device.id}
|
key={device.id}
|
||||||
className="text-sm text-muted-foreground"
|
className="text-sm text-muted-foreground"
|
||||||
>
|
>
|
||||||
{device.name}
|
{device.name}
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ol>
|
</ol>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell className="font-medium">
|
<TableCell className="font-medium">
|
||||||
{payment.number_of_months} Months
|
{payment.number_of_months} Months
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<span className="font-semibold pr-2">
|
<span className="font-semibold pr-2">
|
||||||
{payment.paid ? (
|
{payment.paid ? (
|
||||||
<Badge
|
<Badge
|
||||||
className={cn(
|
className={cn(
|
||||||
payment.status === "PENDING"
|
payment.status === "PENDING"
|
||||||
? "bg-yellow-100 text-yellow-700 dark:bg-yellow-700 dark:text-yellow-100"
|
? "bg-yellow-100 text-yellow-700 dark:bg-yellow-700 dark:text-yellow-100"
|
||||||
: "bg-green-100 dark:bg-green-700",
|
: "bg-green-100 dark:bg-green-700",
|
||||||
)}
|
)}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
>
|
>
|
||||||
{payment.status}
|
{payment.status}
|
||||||
</Badge>
|
</Badge>
|
||||||
) : payment.is_expired ? (
|
) : payment.is_expired ? (
|
||||||
<Badge>Expired</Badge>
|
<Badge>Expired</Badge>
|
||||||
) : (
|
) : (
|
||||||
<Badge variant="outline">{payment.status}</Badge>
|
<Badge variant="outline">{payment.status}</Badge>
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<span className="font-semibold pr-2">
|
<span className="font-semibold pr-2">
|
||||||
{payment.amount.toFixed(2)}
|
{payment.amount.toFixed(2)}
|
||||||
</span>
|
</span>
|
||||||
MVR
|
MVR
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
<TableFooter>
|
<TableFooter>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell colSpan={4} className="text-muted-foreground">
|
<TableCell colSpan={4} className="text-muted-foreground">
|
||||||
{meta?.total === 1 ? (
|
{meta?.total === 1 ? (
|
||||||
<p className="text-center">
|
<p className="text-center">
|
||||||
Total {meta?.total} payment.
|
Total {meta?.total} payment.
|
||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
<p className="text-center">
|
<p className="text-center">
|
||||||
Total {meta?.total} payments.
|
Total {meta?.total} payments.
|
||||||
</p>
|
</p>
|
||||||
)}{" "}
|
)}{" "}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableFooter>
|
</TableFooter>
|
||||||
</Table>
|
</Table>
|
||||||
<Pagination
|
<Pagination
|
||||||
totalPages={meta.last_page}
|
totalPages={meta.last_page}
|
||||||
currentPage={meta.current_page}
|
currentPage={meta.current_page}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="sm:hidden block">
|
<div className="sm:hidden block">
|
||||||
{data.map((payment) => (
|
{data.map((payment) => (
|
||||||
<MobilePaymentDetails key={payment.id} payment={payment} />
|
<MobilePaymentDetails key={payment.id} payment={payment} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function MobilePaymentDetails({
|
export function MobilePaymentDetails({
|
||||||
payment,
|
payment,
|
||||||
isAdmin = false,
|
isAdmin = false,
|
||||||
}: {
|
}: {
|
||||||
payment: Payment;
|
payment: Payment;
|
||||||
isAdmin?: boolean;
|
isAdmin?: boolean;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex flex-col items-start border rounded p-2 my-2",
|
"flex flex-col items-start border rounded p-2 my-2",
|
||||||
payment?.paid
|
payment?.paid
|
||||||
? "bg-green-500/10 border-dashed border-green-500"
|
? "bg-green-500/10 border-dashed border-green-500"
|
||||||
: payment?.is_expired
|
: payment?.is_expired
|
||||||
? "bg-gray-500/10 border-dashed border-gray-500 dark:border-gray-500/50"
|
? "bg-gray-500/10 border-dashed border-gray-500 dark:border-gray-500/50"
|
||||||
: "bg-yellow-500/10 border-dashed border-yellow-500 dark:border-yellow-500/50",
|
: "bg-yellow-500/10 border-dashed border-yellow-500 dark:border-yellow-500/50",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<Calendar size={16} opacity={0.5} />
|
<Calendar size={16} opacity={0.5} />
|
||||||
<span className="text-muted-foreground text-sm">
|
<span className="text-muted-foreground text-sm">
|
||||||
{new Date(payment.created_at).toLocaleDateString("en-US", {
|
{new Date(payment.created_at).toLocaleDateString("en-US", {
|
||||||
month: "short",
|
month: "short",
|
||||||
day: "2-digit",
|
day: "2-digit",
|
||||||
year: "numeric",
|
year: "numeric",
|
||||||
minute: "2-digit",
|
minute: "2-digit",
|
||||||
hour: "2-digit",
|
hour: "2-digit",
|
||||||
timeZone: "Indian/Maldives", // Force consistent timezone
|
timeZone: "Indian/Maldives", // Force consistent timezone
|
||||||
})}
|
})}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center gap-2 mt-2">
|
<div className="flex items-center gap-2 mt-2">
|
||||||
<Link
|
<Link
|
||||||
className="font-medium hover:underline"
|
className="font-medium hover:underline"
|
||||||
href={`/payments/${payment.id}`}
|
href={`/payments/${payment.id}`}
|
||||||
>
|
>
|
||||||
<Button size={"sm"} variant="outline">
|
<Button size={"sm"} variant="outline">
|
||||||
View Details
|
View Details
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
<div className="bg-white dark:bg-black p-2 rounded mt-2 w-full border">
|
<div className="bg-white dark:bg-black p-2 rounded mt-2 w-full border">
|
||||||
<h3 className="text-sm font-medium">Devices</h3>
|
<h3 className="text-sm font-medium">Devices</h3>
|
||||||
<ol className="list-disc list-inside text-sm">
|
<ol className="list-disc list-inside text-sm">
|
||||||
{payment.devices.map((device) => (
|
{payment.devices.map((device) => (
|
||||||
<li key={device.id} className="text-sm text-muted-foreground">
|
<li key={device.id} className="text-sm text-muted-foreground">
|
||||||
{device.name}
|
{device.name}
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ol>
|
</ol>
|
||||||
<div className="block sm:hidden">
|
<div className="block sm:hidden">
|
||||||
<Separator className="my-2" />
|
<Separator className="my-2" />
|
||||||
<h3 className="text-sm font-medium">Duration</h3>
|
<h3 className="text-sm font-medium">Duration</h3>
|
||||||
<span className="text-sm text-muted-foreground">
|
<span className="text-sm text-muted-foreground">
|
||||||
{payment.number_of_months} Months
|
{payment.number_of_months} Months
|
||||||
</span>
|
</span>
|
||||||
<Separator className="my-2" />
|
<Separator className="my-2" />
|
||||||
<h3 className="text-sm font-medium">Amount</h3>
|
<h3 className="text-sm font-medium">Amount</h3>
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<span className="text-sm text-muted-foreground">
|
<span className="text-sm text-muted-foreground">
|
||||||
{payment.amount.toFixed(2)} MVR
|
{payment.amount.toFixed(2)} MVR
|
||||||
</span>
|
</span>
|
||||||
<span className="font-semibold pr-2">
|
<span className="font-semibold pr-2">
|
||||||
{payment.paid ? (
|
{payment.paid ? (
|
||||||
<Badge
|
<Badge
|
||||||
className={cn(
|
className={cn(
|
||||||
payment.status === "PENDING"
|
payment.status === "PENDING"
|
||||||
? "bg-yellow-100 text-yellow-700 dark:bg-yellow-700 dark:text-yellow-100"
|
? "bg-yellow-100 text-yellow-700 dark:bg-yellow-700 dark:text-yellow-100"
|
||||||
: "bg-green-100 dark:bg-green-700",
|
: "bg-green-100 dark:bg-green-700",
|
||||||
)}
|
)}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
>
|
>
|
||||||
{payment.status}
|
{payment.status}
|
||||||
</Badge>
|
</Badge>
|
||||||
) : payment.is_expired ? (
|
) : payment.is_expired ? (
|
||||||
<Badge>Expired</Badge>
|
<Badge>Expired</Badge>
|
||||||
) : (
|
) : (
|
||||||
<Badge variant="secondary">{payment.status}</Badge>
|
<Badge variant="secondary">{payment.status}</Badge>
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
{isAdmin && (
|
{isAdmin && (
|
||||||
<div className="my-2 text-primary flex flex-col items-start text-sm border rounded p-2 mt-2 w-full bg-white dark:bg-black">
|
<div className="my-2 text-primary flex flex-col items-start text-sm border rounded p-2 mt-2 w-full bg-white dark:bg-black">
|
||||||
{payment?.user?.name}
|
{payment?.user?.name}
|
||||||
<span className="text-muted-foreground">
|
<span className="text-muted-foreground">
|
||||||
{payment?.user?.id_card}
|
{payment?.user?.id_card}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,151 +3,155 @@ import { BadgeDollarSign, Loader2 } from "lucide-react";
|
|||||||
import { useActionState, useEffect } from "react";
|
import { useActionState, useEffect } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import {
|
import {
|
||||||
type VerifyTopupPaymentState,
|
type VerifyTopupPaymentState,
|
||||||
verifyTopupPayment,
|
verifyTopupPayment,
|
||||||
} from "@/actions/payment";
|
} from "@/actions/payment";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCaption,
|
TableCaption,
|
||||||
TableCell,
|
TableCell,
|
||||||
TableFooter,
|
TableFooter,
|
||||||
TableRow,
|
TableRow,
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import type { Topup } from "@/lib/backend-types";
|
import type { Topup } from "@/lib/backend-types";
|
||||||
import { AccountInfomation } from "./account-information";
|
import { AccountInfomation } from "./account-information";
|
||||||
import { Button } from "./ui/button";
|
import { Button } from "./ui/button";
|
||||||
|
|
||||||
const initialState: VerifyTopupPaymentState = {
|
const initialState: VerifyTopupPaymentState = {
|
||||||
message: "",
|
message: "",
|
||||||
success: false,
|
success: false,
|
||||||
fieldErrors: {},
|
fieldErrors: {},
|
||||||
};
|
};
|
||||||
export default function TopupToPay({
|
export default function TopupToPay({
|
||||||
topup,
|
topup,
|
||||||
disabled,
|
disabled,
|
||||||
}: {
|
}: {
|
||||||
topup?: Topup;
|
topup?: Topup;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
}) {
|
}) {
|
||||||
const [state, formAction, isPending] = useActionState(
|
const [state, formAction, isPending] = useActionState(
|
||||||
verifyTopupPayment,
|
verifyTopupPayment,
|
||||||
initialState,
|
initialState,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Handle toast notifications based on state changes
|
// Handle toast notifications based on state changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (state.success && state.message) {
|
if (state.success && state.message) {
|
||||||
toast.success("Topup successful!", {
|
toast.success("Topup successful!", {
|
||||||
closeButton: true,
|
closeButton: true,
|
||||||
description: state.transaction
|
description: state.transaction
|
||||||
? `Your topup payment has been verified successfully using ${state.transaction.sourceBank} bank transfer on ${state.transaction.trxDate}.`
|
? `Your topup payment has been verified successfully using ${state.transaction.sourceBank} bank transfer on ${state.transaction.trxDate}.`
|
||||||
: state.message,
|
: state.message,
|
||||||
});
|
});
|
||||||
} else if (
|
} else if (
|
||||||
!state.success &&
|
!state.success &&
|
||||||
state.message &&
|
state.message &&
|
||||||
state.message !== initialState.message
|
state.message !== initialState.message
|
||||||
) {
|
) {
|
||||||
toast.error("Topup Payment Verification Failed", {
|
toast.error("Topup Payment Verification Failed", {
|
||||||
closeButton: true,
|
closeButton: true,
|
||||||
description: state.message,
|
description: state.message,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [state]);
|
}, [state]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<div className="m-2 flex items-end justify-end p-2 text-sm text-foreground border rounded">
|
<div className="m-2 flex items-end justify-end p-2 text-sm text-foreground border rounded">
|
||||||
<Table>
|
<Table>
|
||||||
<TableCaption>
|
<TableCaption>
|
||||||
<div className="max-w-sm mx-auto">
|
{!topup?.paid ||
|
||||||
<p>Please send the following amount to the payment address</p>
|
topup?.is_expired ||
|
||||||
<AccountInfomation
|
(topup?.status !== "CANCELLED" && (
|
||||||
accName="Baraveli Dev"
|
<div className="max-w-sm mx-auto">
|
||||||
accountNo="90101400028321000"
|
<p>Please send the following amount to the payment address</p>
|
||||||
/>
|
<AccountInfomation
|
||||||
{topup?.paid ? (
|
accName="Baraveli Dev"
|
||||||
<Button
|
accountNo="90101400028321000"
|
||||||
size={"lg"}
|
/>
|
||||||
variant={"secondary"}
|
{topup?.paid ? (
|
||||||
disabled
|
<Button
|
||||||
className="dark:text-green-200 text-green-900 bg-green-500/20 uppercase font-semibold"
|
size={"lg"}
|
||||||
>
|
variant={"secondary"}
|
||||||
Topup Payment Verified
|
disabled
|
||||||
</Button>
|
className="dark:text-green-200 text-green-900 bg-green-500/20 uppercase font-semibold"
|
||||||
) : (
|
>
|
||||||
<div className="flex flex-col gap-2">
|
Topup Payment Verified
|
||||||
<form action={formAction}>
|
</Button>
|
||||||
<input
|
) : (
|
||||||
type="hidden"
|
<div className="flex flex-col gap-2">
|
||||||
name="topupId"
|
<form action={formAction}>
|
||||||
value={topup?.id ?? ""}
|
<input
|
||||||
/>
|
type="hidden"
|
||||||
<Button
|
name="topupId"
|
||||||
disabled={disabled || isPending}
|
value={topup?.id ?? ""}
|
||||||
type="submit"
|
/>
|
||||||
size={"lg"}
|
<Button
|
||||||
className="mb-4 w-full"
|
disabled={disabled || isPending}
|
||||||
>
|
type="submit"
|
||||||
{isPending ? "Processing payment..." : "I have paid"}
|
size={"lg"}
|
||||||
{isPending ? (
|
className="mb-4 w-full"
|
||||||
<Loader2 className="animate-spin" />
|
>
|
||||||
) : (
|
{isPending ? "Processing payment..." : "I have paid"}
|
||||||
<BadgeDollarSign />
|
{isPending ? (
|
||||||
)}
|
<Loader2 className="animate-spin" />
|
||||||
</Button>
|
) : (
|
||||||
</form>
|
<BadgeDollarSign />
|
||||||
</div>
|
)}
|
||||||
)}
|
</Button>
|
||||||
</div>
|
</form>
|
||||||
</TableCaption>
|
</div>
|
||||||
<TableBody className="">
|
)}
|
||||||
<TableRow>
|
</div>
|
||||||
<TableCell>Topup created</TableCell>
|
))}
|
||||||
<TableCell className="text-right text-muted-foreground">
|
</TableCaption>
|
||||||
{new Date(topup?.created_at ?? "").toLocaleDateString("en-US", {
|
<TableBody className="">
|
||||||
month: "short",
|
<TableRow>
|
||||||
day: "2-digit",
|
<TableCell>Topup created</TableCell>
|
||||||
year: "numeric",
|
<TableCell className="text-right text-muted-foreground">
|
||||||
minute: "2-digit",
|
{new Date(topup?.created_at ?? "").toLocaleDateString("en-US", {
|
||||||
hour: "2-digit",
|
month: "short",
|
||||||
second: "2-digit",
|
day: "2-digit",
|
||||||
})}
|
year: "numeric",
|
||||||
</TableCell>
|
minute: "2-digit",
|
||||||
</TableRow>
|
hour: "2-digit",
|
||||||
<TableRow>
|
second: "2-digit",
|
||||||
<TableCell>Payment received</TableCell>
|
})}
|
||||||
<TableCell className="text-right text-sarLinkOrange">
|
</TableCell>
|
||||||
{topup?.paid_at
|
</TableRow>
|
||||||
? new Date(topup.paid_at).toLocaleDateString("en-US", {
|
<TableRow>
|
||||||
month: "short",
|
<TableCell>Payment received</TableCell>
|
||||||
day: "2-digit",
|
<TableCell className="text-right text-sarLinkOrange">
|
||||||
year: "numeric",
|
{topup?.paid_at
|
||||||
minute: "2-digit",
|
? new Date(topup.paid_at).toLocaleDateString("en-US", {
|
||||||
hour: "2-digit",
|
month: "short",
|
||||||
second: "2-digit",
|
day: "2-digit",
|
||||||
})
|
year: "numeric",
|
||||||
: "-"}
|
minute: "2-digit",
|
||||||
</TableCell>
|
hour: "2-digit",
|
||||||
</TableRow>
|
second: "2-digit",
|
||||||
<TableRow>
|
})
|
||||||
<TableCell>MIB Reference</TableCell>
|
: "-"}
|
||||||
<TableCell className="text-right">
|
</TableCell>
|
||||||
{topup?.mib_reference ? topup.mib_reference : "-"}
|
</TableRow>
|
||||||
</TableCell>
|
<TableRow>
|
||||||
</TableRow>
|
<TableCell>MIB Reference</TableCell>
|
||||||
</TableBody>
|
<TableCell className="text-right">
|
||||||
<TableFooter>
|
{topup?.mib_reference ? topup.mib_reference : "-"}
|
||||||
<TableRow className="">
|
</TableCell>
|
||||||
<TableCell colSpan={1}>Total Due</TableCell>
|
</TableRow>
|
||||||
<TableCell className="text-right text-3xl font-bold">
|
</TableBody>
|
||||||
{topup?.amount?.toFixed(2)}
|
<TableFooter>
|
||||||
</TableCell>
|
<TableRow className="">
|
||||||
</TableRow>
|
<TableCell colSpan={1}>Total Due</TableCell>
|
||||||
</TableFooter>
|
<TableCell className="text-right text-3xl font-bold">
|
||||||
</Table>
|
{topup?.amount?.toFixed(2)}
|
||||||
</div>
|
</TableCell>
|
||||||
</div>
|
</TableRow>
|
||||||
);
|
</TableFooter>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,13 @@ import Link from "next/link";
|
|||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { getTopups } from "@/actions/payment";
|
import { getTopups } from "@/actions/payment";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCaption,
|
TableCell,
|
||||||
TableCell,
|
TableFooter,
|
||||||
TableFooter,
|
TableHead,
|
||||||
TableHead,
|
TableHeader,
|
||||||
TableHeader,
|
TableRow,
|
||||||
TableRow,
|
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import type { Topup } from "@/lib/backend-types";
|
import type { Topup } from "@/lib/backend-types";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
@@ -20,200 +19,199 @@ import { Badge } from "./ui/badge";
|
|||||||
import { Button } from "./ui/button";
|
import { Button } from "./ui/button";
|
||||||
|
|
||||||
export async function TopupsTable({
|
export async function TopupsTable({
|
||||||
searchParams,
|
searchParams,
|
||||||
}: {
|
}: {
|
||||||
searchParams: Promise<{
|
searchParams: Promise<{
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
}>;
|
}>;
|
||||||
}) {
|
}) {
|
||||||
const resolvedParams = await searchParams;
|
const resolvedParams = await searchParams;
|
||||||
const page = Number.parseInt(resolvedParams.page as string) || 1;
|
const page = Number.parseInt(resolvedParams.page as string) || 1;
|
||||||
const limit = 10;
|
const limit = 10;
|
||||||
const offset = (page - 1) * limit;
|
const offset = (page - 1) * limit;
|
||||||
// Build params object
|
// Build params object
|
||||||
const apiParams: Record<string, string | number | undefined> = {};
|
const apiParams: Record<string, string | number | undefined> = {};
|
||||||
for (const [key, value] of Object.entries(resolvedParams)) {
|
for (const [key, value] of Object.entries(resolvedParams)) {
|
||||||
if (value !== undefined && value !== "") {
|
if (value !== undefined && value !== "") {
|
||||||
apiParams[key] = typeof value === "number" ? value : String(value);
|
apiParams[key] = typeof value === "number" ? value : String(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
apiParams.limit = limit;
|
apiParams.limit = limit;
|
||||||
apiParams.offset = offset;
|
apiParams.offset = offset;
|
||||||
const [error, topups] = await tryCatch(getTopups(apiParams));
|
const [error, topups] = await tryCatch(getTopups(apiParams));
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
if (error.message.includes("Unauthorized")) {
|
if (error.message.includes("Unauthorized")) {
|
||||||
redirect("/auth/signin");
|
redirect("/auth/signin");
|
||||||
} else {
|
} else {
|
||||||
return <pre>{JSON.stringify(error, null, 2)}</pre>;
|
return <pre>{JSON.stringify(error, null, 2)}</pre>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const { data, meta } = topups;
|
const { data, meta } = topups;
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{data?.length === 0 ? (
|
{data?.length === 0 ? (
|
||||||
<div className="h-[calc(100svh-400px)] flex text-muted-foreground flex-col items-center justify-center my-4">
|
<div className="h-[calc(100svh-400px)] flex text-muted-foreground flex-col items-center justify-center my-4">
|
||||||
<h3>No topups.</h3>
|
<h3>No topups.</h3>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<div className="hidden sm:block">
|
<div className="hidden sm:block">
|
||||||
<Table className="overflow-scroll">
|
<Table className="overflow-scroll">
|
||||||
<TableCaption>Table of all topups.</TableCaption>
|
<TableHeader>
|
||||||
<TableHeader>
|
<TableRow>
|
||||||
<TableRow>
|
<TableHead>Details</TableHead>
|
||||||
<TableHead>Details</TableHead>
|
<TableHead>Status</TableHead>
|
||||||
<TableHead>Status</TableHead>
|
<TableHead>Amount</TableHead>
|
||||||
<TableHead>Amount</TableHead>
|
</TableRow>
|
||||||
</TableRow>
|
</TableHeader>
|
||||||
</TableHeader>
|
<TableBody className="overflow-scroll">
|
||||||
<TableBody className="overflow-scroll">
|
{topups?.data?.map((topup) => (
|
||||||
{topups?.data?.map((topup) => (
|
<TableRow key={topup.id}>
|
||||||
<TableRow key={topup.id}>
|
<TableCell>
|
||||||
<TableCell>
|
<div
|
||||||
<div
|
className={cn(
|
||||||
className={cn(
|
"flex flex-col items-start border rounded p-2",
|
||||||
"flex flex-col items-start border rounded p-2",
|
topup?.paid
|
||||||
topup?.paid
|
? "bg-green-500/10 border-dashed border-green-500"
|
||||||
? "bg-green-500/10 border-dashed border-green-500"
|
: topup?.is_expired
|
||||||
: topup?.is_expired
|
? "bg-gray-500/10 border-dashed border-gray-500 dark:border-gray-500/50"
|
||||||
? "bg-gray-500/10 border-dashed border-gray-500 dark:border-gray-500/50"
|
: "bg-yellow-500/10 border-dashed border-yellow-500 dark:border-yellow-500/50",
|
||||||
: "bg-yellow-500/10 border-dashed border-yellow-500 dark:border-yellow-500/50",
|
)}
|
||||||
)}
|
>
|
||||||
>
|
<div className="flex items-center gap-2">
|
||||||
<div className="flex items-center gap-2">
|
<Calendar size={16} opacity={0.5} />
|
||||||
<Calendar size={16} opacity={0.5} />
|
<span className="text-muted-foreground">
|
||||||
<span className="text-muted-foreground">
|
{new Date(topup.created_at).toLocaleDateString(
|
||||||
{new Date(topup.created_at).toLocaleDateString(
|
"en-US",
|
||||||
"en-US",
|
{
|
||||||
{
|
month: "short",
|
||||||
month: "short",
|
day: "2-digit",
|
||||||
day: "2-digit",
|
year: "numeric",
|
||||||
year: "numeric",
|
minute: "2-digit",
|
||||||
minute: "2-digit",
|
hour: "2-digit",
|
||||||
hour: "2-digit",
|
},
|
||||||
},
|
)}
|
||||||
)}
|
</span>
|
||||||
</span>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex items-center gap-2 mt-2">
|
<div className="flex items-center gap-2 mt-2">
|
||||||
<Link
|
<Link
|
||||||
className="font-medium hover:underline"
|
className="font-medium hover:underline"
|
||||||
href={`/top-ups/${topup.id}`}
|
href={`/top-ups/${topup.id}`}
|
||||||
>
|
>
|
||||||
<Button size={"sm"} variant="outline">
|
<Button size={"sm"} variant="outline">
|
||||||
View Details
|
View Details
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<span className="font-semibold pr-2">
|
<span className="font-semibold pr-2">
|
||||||
{topup.paid ? (
|
{topup.paid ? (
|
||||||
<Badge
|
<Badge
|
||||||
className="bg-green-100 dark:bg-green-700"
|
className="bg-green-100 dark:bg-green-700"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
>
|
>
|
||||||
{topup.status}
|
{topup.status}
|
||||||
</Badge>
|
</Badge>
|
||||||
) : topup.is_expired ? (
|
) : topup.is_expired ? (
|
||||||
<Badge>Expired</Badge>
|
<Badge>Expired</Badge>
|
||||||
) : (
|
) : (
|
||||||
<Badge variant="outline">{topup.status}</Badge>
|
<Badge variant="outline">{topup.status}</Badge>
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<span className="font-semibold pr-2">
|
<span className="font-semibold pr-2">
|
||||||
{topup.amount.toFixed(2)}
|
{topup.amount.toFixed(2)}
|
||||||
</span>
|
</span>
|
||||||
MVR
|
MVR
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
<TableFooter>
|
<TableFooter>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell colSpan={4} className="text-muted-foreground">
|
<TableCell colSpan={4} className="text-muted-foreground">
|
||||||
{meta?.total === 1 ? (
|
{meta?.total === 1 ? (
|
||||||
<p className="text-center">Total {meta?.total} topup.</p>
|
<p className="text-center">Total {meta?.total} topup.</p>
|
||||||
) : (
|
) : (
|
||||||
<p className="text-center">Total {meta?.total} topups.</p>
|
<p className="text-center">Total {meta?.total} topups.</p>
|
||||||
)}
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableFooter>
|
</TableFooter>
|
||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
<div className="sm:hidden block">
|
<div className="sm:hidden block">
|
||||||
{data.map((topup) => (
|
{data.map((topup) => (
|
||||||
<MobileTopupDetails key={topup.id} topup={topup} />
|
<MobileTopupDetails key={topup.id} topup={topup} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
<Pagination
|
<Pagination
|
||||||
totalPages={meta?.last_page}
|
totalPages={meta?.last_page}
|
||||||
currentPage={meta?.current_page}
|
currentPage={meta?.current_page}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function MobileTopupDetails({ topup }: { topup: Topup }) {
|
function MobileTopupDetails({ topup }: { topup: Topup }) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex flex-col items-start border rounded p-2 my-2",
|
"flex flex-col items-start border rounded p-2 my-2",
|
||||||
topup?.paid
|
topup?.paid
|
||||||
? "bg-green-500/10 border-dashed border-green=500"
|
? "bg-green-500/10 border-dashed border-green=500"
|
||||||
: "bg-yellow-500/10 border-dashed border-yellow-500 dark:border-yellow-500/50",
|
: "bg-yellow-500/10 border-dashed border-yellow-500 dark:border-yellow-500/50",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<Calendar size={16} opacity={0.5} />
|
<Calendar size={16} opacity={0.5} />
|
||||||
<span className="text-muted-foreground text-sm">
|
<span className="text-muted-foreground text-sm">
|
||||||
{new Date(topup.created_at).toLocaleDateString("en-US", {
|
{new Date(topup.created_at).toLocaleDateString("en-US", {
|
||||||
month: "short",
|
month: "short",
|
||||||
day: "2-digit",
|
day: "2-digit",
|
||||||
year: "numeric",
|
year: "numeric",
|
||||||
})}
|
})}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center gap-2 mt-2">
|
<div className="flex items-center gap-2 mt-2">
|
||||||
<Link
|
<Link
|
||||||
className="font-medium hover:underline"
|
className="font-medium hover:underline"
|
||||||
href={`/top-ups/${topup.id}`}
|
href={`/top-ups/${topup.id}`}
|
||||||
>
|
>
|
||||||
<Button size={"sm"} variant="outline">
|
<Button size={"sm"} variant="outline">
|
||||||
View Details
|
View Details
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="bg-white dark:bg-black p-2 rounded mt-2 w-full border flex justify-between items-center">
|
<div className="bg-white dark:bg-black p-2 rounded mt-2 w-full border flex justify-between items-center">
|
||||||
<div className="block sm:hidden">
|
<div className="block sm:hidden">
|
||||||
<h3 className="text-sm font-medium">Amount</h3>
|
<h3 className="text-sm font-medium">Amount</h3>
|
||||||
<span className="text-sm text-muted-foreground">
|
<span className="text-sm text-muted-foreground">
|
||||||
{topup.amount.toFixed(2)} MVR
|
{topup.amount.toFixed(2)} MVR
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<span className="font-semibold pr-2">
|
<span className="font-semibold pr-2">
|
||||||
{topup.paid ? (
|
{topup.paid ? (
|
||||||
<Badge className="bg-green-100 dark:bg-green-700" variant="outline">
|
<Badge className="bg-green-100 dark:bg-green-700" variant="outline">
|
||||||
{topup.status}
|
{topup.status}
|
||||||
</Badge>
|
</Badge>
|
||||||
) : topup.is_expired ? (
|
) : topup.is_expired ? (
|
||||||
<Badge>Expired</Badge>
|
<Badge>Expired</Badge>
|
||||||
) : (
|
) : (
|
||||||
<Badge variant="secondary">{topup.status}</Badge>
|
<Badge variant="secondary">{topup.status}</Badge>
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,3 @@
|
|||||||
// import {
|
|
||||||
// Table,
|
|
||||||
// TableBody,
|
|
||||||
// TableCaption,
|
|
||||||
// TableCell,
|
|
||||||
// TableFooter,
|
|
||||||
// TableHead,
|
|
||||||
// TableHeader,
|
|
||||||
// TableRow,
|
|
||||||
// } from "@/components/ui/table";
|
|
||||||
// import Link from "next/link";
|
|
||||||
// import Pagination from "./pagination";
|
|
||||||
// import { Badge } from "./ui/badge";
|
|
||||||
// import { Button } from "./ui/button";
|
|
||||||
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { getUsers } from "@/queries/users";
|
import { getUsers } from "@/queries/users";
|
||||||
@@ -22,136 +7,134 @@ import Pagination from "./pagination";
|
|||||||
import { Badge } from "./ui/badge";
|
import { Badge } from "./ui/badge";
|
||||||
import { Button } from "./ui/button";
|
import { Button } from "./ui/button";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCaption,
|
TableCell,
|
||||||
TableCell,
|
TableFooter,
|
||||||
TableFooter,
|
TableHead,
|
||||||
TableHead,
|
TableHeader,
|
||||||
TableHeader,
|
TableRow,
|
||||||
TableRow,
|
|
||||||
} from "./ui/table";
|
} from "./ui/table";
|
||||||
|
|
||||||
export async function UsersTable({
|
export async function UsersTable({
|
||||||
searchParams,
|
searchParams,
|
||||||
}: {
|
}: {
|
||||||
searchParams: Promise<{
|
searchParams: Promise<{
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
}>;
|
}>;
|
||||||
}) {
|
}) {
|
||||||
const resolvedParams = await searchParams;
|
const resolvedParams = await searchParams;
|
||||||
|
|
||||||
const page = Number.parseInt(resolvedParams.page as string) || 1;
|
const page = Number.parseInt(resolvedParams.page as string) || 1;
|
||||||
const limit = 10;
|
const limit = 10;
|
||||||
const offset = (page - 1) * limit;
|
const offset = (page - 1) * limit;
|
||||||
const apiParams: Record<string, string | number | undefined> = {};
|
const apiParams: Record<string, string | number | undefined> = {};
|
||||||
for (const [key, value] of Object.entries(resolvedParams)) {
|
for (const [key, value] of Object.entries(resolvedParams)) {
|
||||||
if (value !== undefined && value !== "") {
|
if (value !== undefined && value !== "") {
|
||||||
apiParams[key] = typeof value === "number" ? value : String(value);
|
apiParams[key] = typeof value === "number" ? value : String(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
apiParams.limit = limit;
|
apiParams.limit = limit;
|
||||||
apiParams.offset = offset;
|
apiParams.offset = offset;
|
||||||
const [error, users] = await tryCatch(getUsers(apiParams));
|
const [error, users] = await tryCatch(getUsers(apiParams));
|
||||||
if (error) {
|
if (error) {
|
||||||
if (error.message === "UNAUTHORIZED") {
|
if (error.message === "UNAUTHORIZED") {
|
||||||
redirect("/auth/signin");
|
redirect("/auth/signin");
|
||||||
}
|
}
|
||||||
return <ClientErrorMessage message={error.message} />;
|
return <ClientErrorMessage message={error.message} />;
|
||||||
}
|
}
|
||||||
const { meta, data } = users;
|
const { meta, data } = users;
|
||||||
|
|
||||||
// return null;
|
// return null;
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{users?.data.length === 0 ? (
|
{users?.data.length === 0 ? (
|
||||||
<div className="h-[calc(100svh-400px)] flex flex-col items-center justify-center my-4">
|
<div className="h-[calc(100svh-400px)] flex flex-col items-center justify-center my-4">
|
||||||
<h3>No Users yet.</h3>
|
<h3>No Users yet.</h3>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<Table className="overflow-scroll">
|
<Table className="overflow-scroll">
|
||||||
<TableCaption>Table of all users.</TableCaption>
|
<TableHeader>
|
||||||
<TableHeader>
|
<TableRow>
|
||||||
<TableRow>
|
<TableHead>Name</TableHead>
|
||||||
<TableHead>Name</TableHead>
|
<TableHead>ID Card</TableHead>
|
||||||
<TableHead>ID Card</TableHead>
|
<TableHead>Atoll</TableHead>
|
||||||
<TableHead>Atoll</TableHead>
|
<TableHead>Island</TableHead>
|
||||||
<TableHead>Island</TableHead>
|
<TableHead>House Name</TableHead>
|
||||||
<TableHead>House Name</TableHead>
|
<TableHead>Status</TableHead>
|
||||||
<TableHead>Status</TableHead>
|
<TableHead>Dob</TableHead>
|
||||||
<TableHead>Dob</TableHead>
|
<TableHead>Phone Number</TableHead>
|
||||||
<TableHead>Phone Number</TableHead>
|
<TableHead>Action</TableHead>
|
||||||
<TableHead>Action</TableHead>
|
</TableRow>
|
||||||
</TableRow>
|
</TableHeader>
|
||||||
</TableHeader>
|
<TableBody className="overflow-scroll">
|
||||||
<TableBody className="overflow-scroll">
|
{data.map((user) => (
|
||||||
{data.map((user) => (
|
<TableRow
|
||||||
<TableRow
|
className={`${user.verified && "title-bg dark:bg-black"}`}
|
||||||
className={`${user.verified && "title-bg dark:bg-black"}`}
|
key={user.id}
|
||||||
key={user.id}
|
>
|
||||||
>
|
<TableCell className="font-medium">
|
||||||
<TableCell className="font-medium">
|
{user.first_name} {user.last_name}
|
||||||
{user.first_name} {user.last_name}
|
</TableCell>
|
||||||
</TableCell>
|
<TableCell className="font-medium">{user.id_card}</TableCell>
|
||||||
<TableCell className="font-medium">{user.id_card}</TableCell>
|
<TableCell>{user.atoll?.name}</TableCell>
|
||||||
<TableCell>{user.atoll?.name}</TableCell>
|
<TableCell>{user.island?.name}</TableCell>
|
||||||
<TableCell>{user.island?.name}</TableCell>
|
<TableCell>{user.address}</TableCell>
|
||||||
<TableCell>{user.address}</TableCell>
|
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{user.verified ? (
|
{user.verified ? (
|
||||||
<Badge
|
<Badge
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="bg-lime-100 text-black"
|
className="bg-lime-100 text-black"
|
||||||
>
|
>
|
||||||
Verified
|
Verified
|
||||||
</Badge>
|
</Badge>
|
||||||
) : (
|
) : (
|
||||||
<Badge
|
<Badge
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="bg-yellow-100 text-black"
|
className="bg-yellow-100 text-black"
|
||||||
>
|
>
|
||||||
Unverified
|
Unverified
|
||||||
</Badge>
|
</Badge>
|
||||||
)}
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{new Date(user.dob ?? "").toLocaleDateString("en-US", {
|
{new Date(user.dob ?? "").toLocaleDateString("en-US", {
|
||||||
month: "short",
|
month: "short",
|
||||||
day: "2-digit",
|
day: "2-digit",
|
||||||
year: "numeric",
|
year: "numeric",
|
||||||
})}
|
})}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell>{user.mobile}</TableCell>
|
<TableCell>{user.mobile}</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Link href={`/users/${user.id}/details`}>
|
<Link href={`/users/${user.id}/details`}>
|
||||||
<Button>Details</Button>
|
<Button>Details</Button>
|
||||||
</Link>
|
</Link>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
<TableFooter>
|
<TableFooter>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell colSpan={9}>
|
<TableCell colSpan={9}>
|
||||||
{meta?.total === 1 ? (
|
{meta?.total === 1 ? (
|
||||||
<p className="text-center">Total {meta?.total} user.</p>
|
<p className="text-center">Total {meta?.total} user.</p>
|
||||||
) : (
|
) : (
|
||||||
<p className="text-center">Total {meta?.total} users.</p>
|
<p className="text-center">Total {meta?.total} users.</p>
|
||||||
)}
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableFooter>
|
</TableFooter>
|
||||||
</Table>
|
</Table>
|
||||||
<Pagination
|
<Pagination
|
||||||
totalPages={meta?.last_page}
|
totalPages={meta?.last_page}
|
||||||
currentPage={meta?.current_page}
|
currentPage={meta?.current_page}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,13 @@ import { Calendar } from "lucide-react";
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCaption,
|
TableCell,
|
||||||
TableCell,
|
TableFooter,
|
||||||
TableFooter,
|
TableHead,
|
||||||
TableHead,
|
TableHeader,
|
||||||
TableHeader,
|
TableRow,
|
||||||
TableRow,
|
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import type { WalletTransaction } from "@/lib/backend-types";
|
import type { WalletTransaction } from "@/lib/backend-types";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
@@ -20,224 +19,223 @@ import { Badge } from "./ui/badge";
|
|||||||
import { Button } from "./ui/button";
|
import { Button } from "./ui/button";
|
||||||
|
|
||||||
export async function WalletTransactionsTable({
|
export async function WalletTransactionsTable({
|
||||||
searchParams,
|
searchParams,
|
||||||
}: {
|
}: {
|
||||||
searchParams: Promise<{
|
searchParams: Promise<{
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
}>;
|
}>;
|
||||||
}) {
|
}) {
|
||||||
const resolvedParams = await searchParams;
|
const resolvedParams = await searchParams;
|
||||||
const page = Number.parseInt(resolvedParams.page as string) || 1;
|
const page = Number.parseInt(resolvedParams.page as string) || 1;
|
||||||
const limit = 10;
|
const limit = 10;
|
||||||
const offset = (page - 1) * limit;
|
const offset = (page - 1) * limit;
|
||||||
// Build params object
|
// Build params object
|
||||||
const apiParams: Record<string, string | number | undefined> = {};
|
const apiParams: Record<string, string | number | undefined> = {};
|
||||||
for (const [key, value] of Object.entries(resolvedParams)) {
|
for (const [key, value] of Object.entries(resolvedParams)) {
|
||||||
if (value !== undefined && value !== "") {
|
if (value !== undefined && value !== "") {
|
||||||
apiParams[key] = typeof value === "number" ? value : String(value);
|
apiParams[key] = typeof value === "number" ? value : String(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
apiParams.limit = limit;
|
apiParams.limit = limit;
|
||||||
apiParams.offset = offset;
|
apiParams.offset = offset;
|
||||||
const [error, transactions] = await tryCatch(
|
const [error, transactions] = await tryCatch(
|
||||||
getWaleltTransactions(apiParams),
|
getWaleltTransactions(apiParams),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
if (error.message.includes("Unauthorized")) {
|
if (error.message.includes("Unauthorized")) {
|
||||||
redirect("/auth/signin");
|
redirect("/auth/signin");
|
||||||
} else {
|
} else {
|
||||||
return <pre>{JSON.stringify(error, null, 2)}</pre>;
|
return <pre>{JSON.stringify(error, null, 2)}</pre>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const { data, meta } = transactions;
|
const { data, meta } = transactions;
|
||||||
const totalDebit = data.reduce(
|
const totalDebit = data.reduce(
|
||||||
(acc, trx) => acc + (trx.transaction_type === "DEBIT" ? trx.amount : 0),
|
(acc, trx) => acc + (trx.transaction_type === "DEBIT" ? trx.amount : 0),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
const totalCredit = data.reduce(
|
const totalCredit = data.reduce(
|
||||||
(acc, trx) => acc + (trx.transaction_type === "TOPUP" ? trx.amount : 0),
|
(acc, trx) => acc + (trx.transaction_type === "TOPUP" ? trx.amount : 0),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{data?.length === 0 ? (
|
{data?.length === 0 ? (
|
||||||
<div className="h-[calc(100svh-400px)] flex flex-col items-center justify-center my-4">
|
<div className="h-[calc(100svh-400px)] flex flex-col items-center justify-center my-4">
|
||||||
<h3>No transactions yet.</h3>
|
<h3>No transactions yet.</h3>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div>
|
<div>
|
||||||
<div className="flex gap-4 mb-4 w-full">
|
<div className="flex gap-4 mb-4 w-full">
|
||||||
<div className="bg-red-400 w-full sm:w-fit dark:bg-red-950 dark:text-red-400 text-red-900 p-2 px-4 rounded-md mb-2">
|
<div className="bg-red-400 w-full sm:w-fit dark:bg-red-950 dark:text-red-400 text-red-900 p-2 px-4 rounded-md mb-2">
|
||||||
<h5 className="text-lg font-semibold">Total Debit</h5>
|
<h5 className="text-lg font-semibold">Total Debit</h5>
|
||||||
<p>{totalDebit.toFixed(2)} MVR</p>
|
<p>{totalDebit.toFixed(2)} MVR</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="bg-green-400 w-full sm:w-fit dark:bg-green-950 dark:text-green-400 text-green-900 p-2 px-4 rounded-md mb-2">
|
<div className="bg-green-400 w-full sm:w-fit dark:bg-green-950 dark:text-green-400 text-green-900 p-2 px-4 rounded-md mb-2">
|
||||||
<h5 className="text-lg font-semibold">Total Credit</h5>
|
<h5 className="text-lg font-semibold">Total Credit</h5>
|
||||||
<p>{totalCredit.toFixed(2)} MVR</p>
|
<p>{totalCredit.toFixed(2)} MVR</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="hidden sm:block">
|
<div className="hidden sm:block">
|
||||||
<Table className="overflow-scroll">
|
<Table className="overflow-scroll">
|
||||||
<TableCaption>Table of all transactions.</TableCaption>
|
<TableHeader>
|
||||||
<TableHeader>
|
<TableRow>
|
||||||
<TableRow>
|
<TableHead>Description</TableHead>
|
||||||
<TableHead>Description</TableHead>
|
<TableHead>Amount</TableHead>
|
||||||
<TableHead>Amount</TableHead>
|
<TableHead>Transaction Type</TableHead>
|
||||||
<TableHead>Transaction Type</TableHead>
|
<TableHead>View Details</TableHead>
|
||||||
<TableHead>View Details</TableHead>
|
<TableHead>Created at</TableHead>
|
||||||
<TableHead>Created at</TableHead>
|
</TableRow>
|
||||||
</TableRow>
|
</TableHeader>
|
||||||
</TableHeader>
|
<TableBody className="overflow-scroll">
|
||||||
<TableBody className="overflow-scroll">
|
{transactions?.data?.map((trx) => (
|
||||||
{transactions?.data?.map((trx) => (
|
<TableRow
|
||||||
<TableRow
|
className={cn(
|
||||||
className={cn(
|
"items-start border rounded p-2",
|
||||||
"items-start border rounded p-2",
|
trx?.transaction_type === "TOPUP"
|
||||||
trx?.transaction_type === "TOPUP"
|
? "credit-bg"
|
||||||
? "credit-bg"
|
: "debit-bg",
|
||||||
: "debit-bg",
|
)}
|
||||||
)}
|
key={trx.id}
|
||||||
key={trx.id}
|
>
|
||||||
>
|
<TableCell>
|
||||||
<TableCell>
|
<span className="text-muted-foreground">
|
||||||
<span className="text-muted-foreground">
|
{trx.description}
|
||||||
{trx.description}
|
</span>
|
||||||
</span>
|
</TableCell>
|
||||||
</TableCell>
|
<TableCell>{trx.amount.toFixed(2)} MVR</TableCell>
|
||||||
<TableCell>{trx.amount.toFixed(2)} MVR</TableCell>
|
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<span className="font-semibold pr-2">
|
<span className="font-semibold pr-2">
|
||||||
{trx.transaction_type === "TOPUP" ? (
|
{trx.transaction_type === "TOPUP" ? (
|
||||||
<Badge className="bg-green-100 text-green-950 dark:bg-green-700">
|
<Badge className="bg-green-100 text-green-950 dark:bg-green-700">
|
||||||
{trx.transaction_type}
|
{trx.transaction_type}
|
||||||
</Badge>
|
</Badge>
|
||||||
) : (
|
) : (
|
||||||
<Badge className="bg-red-500 text-red-950 dark:bg-red-700">
|
<Badge className="bg-red-500 text-red-950 dark:bg-red-700">
|
||||||
{trx.transaction_type}
|
{trx.transaction_type}
|
||||||
</Badge>
|
</Badge>
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<span className="">
|
<span className="">
|
||||||
{new Date(trx.created_at).toLocaleDateString("en-US", {
|
{new Date(trx.created_at).toLocaleDateString("en-US", {
|
||||||
month: "short",
|
month: "short",
|
||||||
day: "2-digit",
|
day: "2-digit",
|
||||||
year: "numeric",
|
year: "numeric",
|
||||||
minute: "2-digit",
|
minute: "2-digit",
|
||||||
hour: "2-digit",
|
hour: "2-digit",
|
||||||
})}
|
})}
|
||||||
</span>
|
</span>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Button>
|
<Button>
|
||||||
<Link
|
<Link
|
||||||
className="font-medium "
|
className="font-medium "
|
||||||
href={
|
href={
|
||||||
trx.transaction_type === "TOPUP"
|
trx.transaction_type === "TOPUP"
|
||||||
? `/top-ups/${trx.reference_id}`
|
? `/top-ups/${trx.reference_id}`
|
||||||
: `/payments/${trx.reference_id}`
|
: `/payments/${trx.reference_id}`
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
View Details
|
View Details
|
||||||
</Link>
|
</Link>
|
||||||
</Button>
|
</Button>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
<TableFooter>
|
<TableFooter>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell colSpan={5} className="text-muted-foreground">
|
<TableCell colSpan={5} className="text-muted-foreground">
|
||||||
{meta?.total === 1 ? (
|
{meta?.total === 1 ? (
|
||||||
<p className="text-center">
|
<p className="text-center">
|
||||||
Total {meta?.total} transaction.
|
Total {meta?.total} transaction.
|
||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
<p className="text-center">
|
<p className="text-center">
|
||||||
Total {meta?.total} transactions.
|
Total {meta?.total} transactions.
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableFooter>
|
</TableFooter>
|
||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
<div className="sm:hidden block">
|
<div className="sm:hidden block">
|
||||||
{data.map((trx) => (
|
{data.map((trx) => (
|
||||||
<MobileTransactionDetails key={trx.id} trx={trx} />
|
<MobileTransactionDetails key={trx.id} trx={trx} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
<Pagination
|
<Pagination
|
||||||
totalPages={meta?.last_page}
|
totalPages={meta?.last_page}
|
||||||
currentPage={meta?.current_page}
|
currentPage={meta?.current_page}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function MobileTransactionDetails({ trx }: { trx: WalletTransaction }) {
|
function MobileTransactionDetails({ trx }: { trx: WalletTransaction }) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex flex-col items-start border rounded p-2 my-2",
|
"flex flex-col items-start border rounded p-2 my-2",
|
||||||
trx?.transaction_type === "TOPUP" ? "credit-bg" : "debit-bg",
|
trx?.transaction_type === "TOPUP" ? "credit-bg" : "debit-bg",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="bg-white shadow dark:bg-black p-2 rounded w-full">
|
<div className="bg-white shadow dark:bg-black p-2 rounded w-full">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<Calendar size={16} opacity={0.5} />
|
<Calendar size={16} opacity={0.5} />
|
||||||
<span className="text-muted-foreground text-sm">
|
<span className="text-muted-foreground text-sm">
|
||||||
{new Date(trx.created_at).toLocaleDateString("en-US", {
|
{new Date(trx.created_at).toLocaleDateString("en-US", {
|
||||||
month: "short",
|
month: "short",
|
||||||
day: "2-digit",
|
day: "2-digit",
|
||||||
year: "numeric",
|
year: "numeric",
|
||||||
minute: "2-digit",
|
minute: "2-digit",
|
||||||
hour: "2-digit",
|
hour: "2-digit",
|
||||||
})}
|
})}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<p className="text-sm text-muted-foreground py-4">{trx.description}</p>
|
<p className="text-sm text-muted-foreground py-4">{trx.description}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="bg-white dark:bg-black p-2 rounded mt-2 w-full border flex justify-between items-center">
|
<div className="bg-white dark:bg-black p-2 rounded mt-2 w-full border flex justify-between items-center">
|
||||||
<div className="block sm:hidden">
|
<div className="block sm:hidden">
|
||||||
<h3 className="text-sm font-medium">Amount</h3>
|
<h3 className="text-sm font-medium">Amount</h3>
|
||||||
<span className="text-sm text-muted-foreground">
|
<span className="text-sm text-muted-foreground">
|
||||||
{trx.amount.toFixed(2)} MVR
|
{trx.amount.toFixed(2)} MVR
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<span className="font-semibold pr-2">
|
<span className="font-semibold pr-2">
|
||||||
{trx.transaction_type === "TOPUP" ? (
|
{trx.transaction_type === "TOPUP" ? (
|
||||||
<Badge className="bg-green-100 text-green-950 dark:bg-green-700">
|
<Badge className="bg-green-100 text-green-950 dark:bg-green-700">
|
||||||
{trx.transaction_type}
|
{trx.transaction_type}
|
||||||
</Badge>
|
</Badge>
|
||||||
) : (
|
) : (
|
||||||
<Badge className="bg-red-500 text-red-950 dark:bg-red-700">
|
<Badge className="bg-red-500 text-red-950 dark:bg-red-700">
|
||||||
{trx.transaction_type}
|
{trx.transaction_type}
|
||||||
</Badge>
|
</Badge>
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-2 mt-2 w-full">
|
<div className="flex items-center gap-2 mt-2 w-full">
|
||||||
<Link
|
<Link
|
||||||
className="font-medium hover:underline"
|
className="font-medium hover:underline"
|
||||||
href={
|
href={
|
||||||
trx.transaction_type === "TOPUP"
|
trx.transaction_type === "TOPUP"
|
||||||
? `/top-ups/${trx.reference_id}`
|
? `/top-ups/${trx.reference_id}`
|
||||||
: `/payments/${trx.reference_id}`
|
: `/payments/${trx.reference_id}`
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Button size={"sm"} className="w-full">
|
<Button size={"sm"} className="w-full">
|
||||||
View Details
|
View Details
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,101 +7,100 @@ import { toast } from "sonner";
|
|||||||
import { createTopup } from "@/actions/payment";
|
import { createTopup } from "@/actions/payment";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
Drawer,
|
Drawer,
|
||||||
DrawerClose,
|
DrawerClose,
|
||||||
DrawerContent,
|
DrawerContent,
|
||||||
DrawerDescription,
|
DrawerDescription,
|
||||||
DrawerFooter,
|
DrawerFooter,
|
||||||
DrawerHeader,
|
DrawerHeader,
|
||||||
DrawerTitle,
|
DrawerTitle,
|
||||||
DrawerTrigger,
|
DrawerTrigger,
|
||||||
} from "@/components/ui/drawer";
|
} from "@/components/ui/drawer";
|
||||||
import { WalletDrawerOpenAtom, walletTopUpValue } from "@/lib/atoms";
|
import { WalletDrawerOpenAtom, walletTopUpValue } from "@/lib/atoms";
|
||||||
import type { TopupType } from "@/lib/types";
|
import type { TopupType } from "@/lib/types";
|
||||||
import NumberInput from "./number-input";
|
import NumberInput from "./number-input";
|
||||||
|
|
||||||
export function Wallet({ walletBalance }: { walletBalance: number }) {
|
export function Wallet({ walletBalance }: { walletBalance: number }) {
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const [amount, setAmount] = useAtom(walletTopUpValue);
|
const [amount, setAmount] = useAtom(walletTopUpValue);
|
||||||
const [isOpen, setIsOpen] = useAtom(WalletDrawerOpenAtom);
|
const [isOpen, setIsOpen] = useAtom(WalletDrawerOpenAtom);
|
||||||
const [disabled, setDisabled] = useState(false);
|
const [disabled, setDisabled] = useState(false);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
if (pathname === "/payment") {
|
if (pathname === "/payment") {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data: TopupType = {
|
const data: TopupType = {
|
||||||
amount: Number.parseFloat(amount.toFixed(2)),
|
amount: Number.parseFloat(amount.toFixed(2)),
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Drawer open={isOpen} onOpenChange={setIsOpen}>
|
<Drawer open={isOpen} onOpenChange={setIsOpen}>
|
||||||
<DrawerTrigger asChild>
|
<DrawerTrigger asChild>
|
||||||
<Button onClick={() => setIsOpen(!isOpen)} variant="outline">
|
<Button onClick={() => setIsOpen(!isOpen)} variant="outline">
|
||||||
{walletBalance}{" "}
|
{walletBalance} MVR
|
||||||
MVR
|
<Wallet2 />
|
||||||
<Wallet2 />
|
</Button>
|
||||||
</Button>
|
</DrawerTrigger>
|
||||||
</DrawerTrigger>
|
<DrawerContent>
|
||||||
<DrawerContent>
|
<div className="mx-auto w-full max-w-sm">
|
||||||
<div className="mx-auto w-full max-w-sm">
|
<DrawerHeader>
|
||||||
<DrawerHeader>
|
<DrawerTitle>Wallet</DrawerTitle>
|
||||||
<DrawerTitle>Wallet</DrawerTitle>
|
<DrawerDescription asChild>
|
||||||
<DrawerDescription asChild>
|
<div>
|
||||||
<div>
|
Your wallet balance is{" "}
|
||||||
Your wallet balance is{" "}
|
<span className="font-semibold">
|
||||||
<span className="font-semibold">
|
{new Intl.NumberFormat("en-US", {
|
||||||
{new Intl.NumberFormat("en-US", {
|
minimumFractionDigits: 2,
|
||||||
minimumFractionDigits: 2,
|
maximumFractionDigits: 2,
|
||||||
maximumFractionDigits: 2,
|
}).format(walletBalance)}
|
||||||
}).format(walletBalance)}
|
</span>{" "}
|
||||||
</span>{" "}
|
</div>
|
||||||
</div>
|
</DrawerDescription>
|
||||||
</DrawerDescription>
|
</DrawerHeader>
|
||||||
</DrawerHeader>
|
|
||||||
|
|
||||||
<div className="px-4 flex flex-col gap-4">
|
<div className="px-4 flex flex-col gap-4">
|
||||||
<NumberInput
|
<NumberInput
|
||||||
label="Set amount to top up"
|
label="Set amount to top up"
|
||||||
value={amount}
|
value={amount}
|
||||||
onChange={(value) => setAmount(value)}
|
onChange={(value) => setAmount(value)}
|
||||||
maxAllowed={5000}
|
maxAllowed={5000}
|
||||||
isDisabled={amount === 0}
|
isDisabled={amount === 0}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<DrawerFooter>
|
<DrawerFooter>
|
||||||
<Button
|
<Button
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
setDisabled(true);
|
setDisabled(true);
|
||||||
const topup = await createTopup(data);
|
const topup = await createTopup(data);
|
||||||
setDisabled(false);
|
setDisabled(false);
|
||||||
if (topup) {
|
if (topup) {
|
||||||
router.push(`/top-ups/${topup.id}`);
|
router.push(`/top-ups/${topup.id}`);
|
||||||
setIsOpen(!isOpen);
|
setIsOpen(!isOpen);
|
||||||
} else {
|
} else {
|
||||||
toast.error("Something went wrong.");
|
toast.error("Something went wrong.");
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
className="w-full"
|
className="w-full"
|
||||||
disabled={amount === 0 || disabled}
|
disabled={amount === 0 || disabled}
|
||||||
>
|
>
|
||||||
{disabled ? (
|
{disabled ? (
|
||||||
<Loader2 className="ml-2 animate-spin" />
|
<Loader2 className="ml-2 animate-spin" />
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
Go to payment
|
Go to payment
|
||||||
<CircleDollarSign />
|
<CircleDollarSign />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
<DrawerClose asChild>
|
<DrawerClose asChild>
|
||||||
<Button variant="outline">Cancel</Button>
|
<Button variant="outline">Cancel</Button>
|
||||||
</DrawerClose>
|
</DrawerClose>
|
||||||
</DrawerFooter>
|
</DrawerFooter>
|
||||||
</div>
|
</div>
|
||||||
</DrawerContent>
|
</DrawerContent>
|
||||||
</Drawer>
|
</Drawer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
22
lib/atoms.ts
22
lib/atoms.ts
@@ -10,7 +10,7 @@ export const discountPercentageAtom = atom(75);
|
|||||||
export const numberOfDevicesAtom = atom(1);
|
export const numberOfDevicesAtom = atom(1);
|
||||||
export const numberOfDaysAtom = atom(30);
|
export const numberOfDaysAtom = atom(30);
|
||||||
export const numberOfMonths = atom(1);
|
export const numberOfMonths = atom(1);
|
||||||
export const walletTopUpValue = atom(1);
|
export const walletTopUpValue = atom(100);
|
||||||
export const formulaResultAtom = atom("");
|
export const formulaResultAtom = atom("");
|
||||||
export const deviceCartAtom = atom<Device[]>([]);
|
export const deviceCartAtom = atom<Device[]>([]);
|
||||||
export const cartDrawerOpenAtom = atom(false);
|
export const cartDrawerOpenAtom = atom(false);
|
||||||
@@ -19,14 +19,14 @@ export const loadingDevicesToPayAtom = atom(false);
|
|||||||
|
|
||||||
// Export the atoms with their store
|
// Export the atoms with their store
|
||||||
export const atoms = {
|
export const atoms = {
|
||||||
initialPriceAtom,
|
initialPriceAtom,
|
||||||
discountPercentageAtom,
|
discountPercentageAtom,
|
||||||
numberOfDevicesAtom,
|
numberOfDevicesAtom,
|
||||||
numberOfDaysAtom,
|
numberOfDaysAtom,
|
||||||
numberOfMonths,
|
numberOfMonths,
|
||||||
formulaResultAtom,
|
formulaResultAtom,
|
||||||
deviceCartAtom,
|
deviceCartAtom,
|
||||||
cartDrawerOpenAtom,
|
cartDrawerOpenAtom,
|
||||||
walletTopUpValue,
|
walletTopUpValue,
|
||||||
loadingDevicesToPayAtom,
|
loadingDevicesToPayAtom,
|
||||||
};
|
};
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "sarlink-portal",
|
"name": "sarlink-portal",
|
||||||
"version": "0.2.1",
|
"version": "0.2.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "sarlink-portal",
|
"name": "sarlink-portal",
|
||||||
"version": "0.2.1",
|
"version": "0.2.2",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@commitlint/cli": "^19.8.1",
|
"@commitlint/cli": "^19.8.1",
|
||||||
"@commitlint/config-conventional": "^19.8.1",
|
"@commitlint/config-conventional": "^19.8.1",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sarlink-portal",
|
"name": "sarlink-portal",
|
||||||
"version": "0.2.1",
|
"version": "0.2.2",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user