mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-11-05 19:27:19 +00:00
Compare commits
51 Commits
feat/cance
...
feat/devic
| Author | SHA1 | Date | |
|---|---|---|---|
| 1a11f1a06c | |||
| 837cc35ad3 | |||
| e984705849 | |||
| 4797ee8dde | |||
| df2b3da22e | |||
| 9e25da717b | |||
|
|
62678b6a84 | ||
| 8c94c92281 | |||
|
|
b3805feefe | ||
| b9d8e56c3c | |||
| d4993530f7 | |||
| 3e3b5f15db | |||
| 13f0e720f4 | |||
| 9fe3c3b774 | |||
| 135edf80a8 | |||
| c0a71dd811 | |||
| 2597ac7d79 | |||
| 154226b48d | |||
| 683d85798a | |||
| da7d101ea6 | |||
| fa0d088f7f | |||
|
5bc8366003
|
|||
|
b22a26a2e8
|
|||
|
f9ed95ae18
|
|||
| 5de4bb9100 | |||
|
|
d5968a5c6b | ||
| 378fb4074c | |||
|
|
15c2713a1b | ||
| ef7121f247 | |||
|
|
a41be97cdf | ||
| 0c7f34fa85 | |||
| 013befa433 | |||
| f4c34d3b7b | |||
|
|
f6e60c0188 | ||
| f3328f7a7b | |||
| ee461bbbf8 | |||
| 89a35a9674 | |||
| cd1dba06f0 | |||
|
|
ed19f440d8 | ||
| c90b003167 | |||
| 40bf8413f8 | |||
| 905b4fa2a6 | |||
| a6d844e8d1 | |||
| 1549b209b3 | |||
|
|
40b9cf8a2e | ||
| 8051b00dcf | |||
|
|
3e3a9af0d7 | ||
| 3cd3bbad16 | |||
| 01b064aee7 | |||
| 0157eccd57 | |||
|
|
4b116df3c0 |
@@ -35,6 +35,11 @@ jobs:
|
|||||||
- name: Deploy production
|
- name: Deploy production
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
run: |
|
run: |
|
||||||
ssh root@10.0.1.5 -t "cd /mnt && docker compose --progress plain pull portal-ui"
|
ssh root@10.0.1.5 -t "cd /mnt && \
|
||||||
ssh root@10.0.1.5 -t "cd /mnt && docker compose --progress plain down portal-ui"
|
docker compose --progress plain pull portal-ui && \
|
||||||
ssh root@10.0.1.5 -t "cd /mnt && docker compose --progress plain up -d portal-ui"
|
docker compose --progress plain down portal-ui && \
|
||||||
|
docker compose --progress plain up -d portal-ui"
|
||||||
|
|
||||||
|
- name: Clean up dangling images
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
run: ssh root@10.0.1.5 -t "docker image prune -f"
|
||||||
|
|||||||
@@ -9,9 +9,11 @@ This is a web portal for SAR Link customers.
|
|||||||
- [x] Add all the filters for devices table (mobile responsive)
|
- [x] Add all the filters for devices table (mobile responsive)
|
||||||
- [x] Add cancel feature to selected devices floating button
|
- [x] Add cancel feature to selected devices floating button
|
||||||
|
|
||||||
### Payments
|
|
||||||
|
### Payments1
|
||||||
- [x] Show payments table
|
- [x] Show payments table
|
||||||
- [x] Add all the filters for payment table (mobile responsive)
|
- [x] Add all the filters for payment table (mobile responsive)
|
||||||
|
- [x] add slider range filter
|
||||||
- [ ] Fix bill formula linking for generated payments
|
- [ ] Fix bill formula linking for generated payments
|
||||||
|
|
||||||
### Parental Control
|
### Parental Control
|
||||||
@@ -33,8 +35,9 @@ This is a web portal for SAR Link customers.
|
|||||||
|
|
||||||
### User Devices
|
### User Devices
|
||||||
- [ ] Block or unblock from admin with custom message
|
- [ ] Block or unblock from admin with custom message
|
||||||
- [ ] Show the devices table
|
- [ ] Blocking devices for client and admin using useActionState instead of client side button onClick handlers
|
||||||
- [ ] Add all relevant filters for user devices table
|
- [ ] Show the devices table
|
||||||
|
- [ ] Add all relevant filters for user devices table
|
||||||
|
|
||||||
### User Payments
|
### User Payments
|
||||||
- [ ] Show user payments table
|
- [ ] Show user payments table
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
"use server";
|
"use server";
|
||||||
|
|
||||||
|
import { revalidatePath } from "next/cache";
|
||||||
import type { GroupProfile, MacAddress, OmadaResponse } from "@/lib/types";
|
import type { GroupProfile, MacAddress, OmadaResponse } from "@/lib/types";
|
||||||
import { formatMacAddress } from "@/lib/utils";
|
import { formatMacAddress } from "@/lib/utils";
|
||||||
import { revalidatePath } from "next/cache";
|
|
||||||
|
|
||||||
async function fetchOmadaGroupProfiles(siteId: string): Promise<OmadaResponse> {
|
async function fetchOmadaGroupProfiles(siteId: string): Promise<OmadaResponse> {
|
||||||
if (!siteId) {
|
if (!siteId) {
|
||||||
|
|||||||
@@ -1,25 +1,31 @@
|
|||||||
"use server";
|
"use server";
|
||||||
|
|
||||||
|
import { revalidatePath } from "next/cache";
|
||||||
|
import { getServerSession } from "next-auth";
|
||||||
import { authOptions } from "@/app/auth";
|
import { authOptions } from "@/app/auth";
|
||||||
import type {
|
import type {
|
||||||
ApiError,
|
ApiError,
|
||||||
ApiResponse,
|
ApiResponse,
|
||||||
NewPayment,
|
NewPayment,
|
||||||
Payment,
|
Payment,
|
||||||
|
Topup
|
||||||
} from "@/lib/backend-types";
|
} from "@/lib/backend-types";
|
||||||
|
import type { TopupResponse } from "@/lib/types";
|
||||||
import type { User } from "@/lib/types/user";
|
import type { User } from "@/lib/types/user";
|
||||||
import { checkSession } from "@/utils/session";
|
import { handleApiResponse } from "@/utils/tryCatch";
|
||||||
import { handleApiResponse, tryCatch } from "@/utils/tryCatch";
|
|
||||||
import { getServerSession } from "next-auth";
|
type GenericGetResponseProps = {
|
||||||
import { revalidatePath } from "next/cache";
|
offset?: number;
|
||||||
import { redirect } from "next/navigation";
|
limit?: number;
|
||||||
|
page?: number;
|
||||||
|
[key: string]: string | number | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
export async function createPayment(data: NewPayment) {
|
export async function createPayment(data: NewPayment) {
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
console.log("data", data);
|
console.log("data", data);
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${
|
`${process.env.SARLINK_API_BASE_URL // });
|
||||||
process.env.SARLINK_API_BASE_URL // });
|
|
||||||
}/api/billing/payment/`,
|
}/api/billing/payment/`,
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -43,6 +49,22 @@ export async function createPayment(data: NewPayment) {
|
|||||||
return payment;
|
return payment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function createTopup(data: { amount: number }) {
|
||||||
|
const session = await getServerSession(authOptions);
|
||||||
|
const response = await fetch(
|
||||||
|
`${process.env.SARLINK_API_BASE_URL}/api/billing/topup/`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Token ${session?.apiToken}`,
|
||||||
|
},
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return handleApiResponse<Topup>(response, "createTopup");
|
||||||
|
}
|
||||||
|
|
||||||
export async function getPayment({ id }: { id: string }) {
|
export async function getPayment({ id }: { id: string }) {
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
@@ -68,10 +90,19 @@ export async function getPayment({ id }: { id: string }) {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPayments() {
|
type GetPaymentProps = {
|
||||||
|
[key: string]: string | number | undefined; // Allow additional properties for flexibility
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function getPayments(params: GetPaymentProps) {
|
||||||
|
// Build query string from all defined params
|
||||||
|
const query = Object.entries(params)
|
||||||
|
.filter(([_, value]) => value !== undefined && value !== "")
|
||||||
|
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)
|
||||||
|
.join("&");
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${process.env.SARLINK_API_BASE_URL}/api/billing/payment/`,
|
`${process.env.SARLINK_API_BASE_URL}/api/billing/payment/?${query}`,
|
||||||
{
|
{
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -92,27 +123,72 @@ export async function getPayments() {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function cancelPayment({ id }: { id: string }) {
|
export async function getTopups(params: GenericGetResponseProps) {
|
||||||
|
|
||||||
|
// Build query string from all defined params
|
||||||
|
const query = Object.entries(params)
|
||||||
|
.filter(([_, value]) => value !== undefined && value !== "")
|
||||||
|
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)
|
||||||
|
.join("&");
|
||||||
|
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${process.env.SARLINK_API_BASE_URL}/api/billing/payment/${id}/delete/`,
|
`${process.env.SARLINK_API_BASE_URL}/api/billing/topup/?${query}`,
|
||||||
{
|
{
|
||||||
method: "DELETE",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: `Token ${session?.apiToken}`,
|
Authorization: `Token ${session?.apiToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if (!response.ok) {
|
return handleApiResponse<ApiResponse<Topup>>(response, "getTopups");
|
||||||
const errorData = (await response.json()) as ApiError;
|
}
|
||||||
const errorMessage =
|
|
||||||
errorData.message || errorData.detail || "An error occurred.";
|
export async function getTopup({ id }: { id: string }) {
|
||||||
const error = new Error(errorMessage);
|
const session = await getServerSession(authOptions);
|
||||||
(error as ApiError & { details?: ApiError }).details = errorData; // Attach the errorData to the error object
|
const response = await fetch(
|
||||||
throw error;
|
`${process.env.SARLINK_API_BASE_URL}/api/billing/topup/${id}`,
|
||||||
}
|
{
|
||||||
return { message: "Payment successfully canceled." };
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Token ${session?.apiToken}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
return handleApiResponse<Topup>(response, "getTopup");
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function cancelTopup({ id }: { id: string }) {
|
||||||
|
const session = await getServerSession(authOptions);
|
||||||
|
const response = await fetch(
|
||||||
|
`${process.env.SARLINK_API_BASE_URL}/api/billing/topup/${id}/cancel/`,
|
||||||
|
{
|
||||||
|
method: "PATCH",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Token ${session?.apiToken}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return handleApiResponse<Topup>(response, "cancelTopup");
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function cancelPayment({ id }: { id: string }) {
|
||||||
|
const session = await getServerSession(authOptions);
|
||||||
|
const response = await fetch(
|
||||||
|
`${process.env.SARLINK_API_BASE_URL}/api/billing/payment/${id}/cancel/`,
|
||||||
|
{
|
||||||
|
method: "PATCH",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Token ${session?.apiToken}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return handleApiResponse<Payment>(response, "cancelPayment");
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdatePayment = {
|
type UpdatePayment = {
|
||||||
@@ -142,6 +218,150 @@ export async function verifyPayment({ id, method }: UpdatePayment) {
|
|||||||
return handleApiResponse<Payment>(response, "updatePayment");
|
return handleApiResponse<Payment>(response, "updatePayment");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type VerifyDevicePaymentState = {
|
||||||
|
payment?: Payment;
|
||||||
|
message: string;
|
||||||
|
success: boolean;
|
||||||
|
fieldErrors: Record<string, string>;
|
||||||
|
payload?: FormData;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function verifyDevicePayment(
|
||||||
|
_prevState: VerifyDevicePaymentState,
|
||||||
|
formData: FormData
|
||||||
|
): Promise<VerifyDevicePaymentState> {
|
||||||
|
const session = await getServerSession(authOptions);
|
||||||
|
|
||||||
|
// Get the payment ID and method from the form data
|
||||||
|
const paymentId = formData.get('paymentId') as string;
|
||||||
|
const method = formData.get('method') as "TRANSFER" | "WALLET";
|
||||||
|
|
||||||
|
if (!paymentId) {
|
||||||
|
return {
|
||||||
|
message: "Payment ID is required",
|
||||||
|
success: false,
|
||||||
|
fieldErrors: { paymentId: "Payment ID is required" },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!method) {
|
||||||
|
return {
|
||||||
|
message: "Payment method is required",
|
||||||
|
success: false,
|
||||||
|
fieldErrors: { method: "Payment method is required" },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(
|
||||||
|
`${process.env.SARLINK_API_BASE_URL}/api/billing/payment/${paymentId}/verify/`,
|
||||||
|
{
|
||||||
|
method: "PUT",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Token ${session?.apiToken}`,
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
method,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = await handleApiResponse<Payment>(response, "verifyDevicePayment");
|
||||||
|
|
||||||
|
revalidatePath("/payments/[paymentId]", "page");
|
||||||
|
|
||||||
|
return {
|
||||||
|
message: method === "WALLET"
|
||||||
|
? "Payment completed successfully using wallet!"
|
||||||
|
: "Payment verification successful!",
|
||||||
|
success: true,
|
||||||
|
fieldErrors: {},
|
||||||
|
payment: result,
|
||||||
|
};
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
message: error.message || "Payment verification failed. Please try again.",
|
||||||
|
success: false,
|
||||||
|
fieldErrors: {},
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
message: "Payment verification failed.",
|
||||||
|
success: false,
|
||||||
|
fieldErrors: {},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export type VerifyTopupPaymentState = {
|
||||||
|
transaction?: {
|
||||||
|
sourceBank: string;
|
||||||
|
trxDate: string;
|
||||||
|
};
|
||||||
|
message: string;
|
||||||
|
success: boolean;
|
||||||
|
fieldErrors: Record<string, string>;
|
||||||
|
payload?: FormData;
|
||||||
|
}
|
||||||
|
export async function verifyTopupPayment(
|
||||||
|
_prevState: VerifyTopupPaymentState,
|
||||||
|
formData: FormData
|
||||||
|
): Promise<VerifyTopupPaymentState> {
|
||||||
|
const session = await getServerSession(authOptions);
|
||||||
|
|
||||||
|
// Get the topup ID from the form data or use a hidden input
|
||||||
|
const topupId = formData.get('topupId') as string;
|
||||||
|
|
||||||
|
if (!topupId) {
|
||||||
|
return {
|
||||||
|
message: "Topup ID is required",
|
||||||
|
success: false,
|
||||||
|
fieldErrors: { topupId: "Topup ID is required" },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(
|
||||||
|
`${process.env.SARLINK_API_BASE_URL}/api/billing/topup/${topupId}/verify/`,
|
||||||
|
{
|
||||||
|
method: "PUT",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Token ${session?.apiToken}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = await handleApiResponse<TopupResponse>(response, "verifyTopupPayment");
|
||||||
|
|
||||||
|
revalidatePath("/top-ups/[topupId]", "page");
|
||||||
|
|
||||||
|
return {
|
||||||
|
message: result.message || "Topup payment verified successfully",
|
||||||
|
success: true,
|
||||||
|
fieldErrors: {},
|
||||||
|
transaction: result.transaction,
|
||||||
|
};
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
message: error.message || "Please check your payment details and try again.",
|
||||||
|
success: false,
|
||||||
|
fieldErrors: {},
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
message: "Topup verification failed.",
|
||||||
|
success: false,
|
||||||
|
fieldErrors: {},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function getProfile() {
|
export async function getProfile() {
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
|
import { getServerSession } from "next-auth";
|
||||||
|
import { Suspense } from "react";
|
||||||
import { authOptions } from "@/app/auth";
|
import { authOptions } from "@/app/auth";
|
||||||
import { DevicesTable } from "@/components/devices-table";
|
import { DevicesTable } from "@/components/devices-table";
|
||||||
import DynamicFilter from "@/components/generic-filter";
|
import DynamicFilter from "@/components/generic-filter";
|
||||||
import AddDeviceDialogForm from "@/components/user/add-device-dialog";
|
import AddDeviceDialogForm from "@/components/user/add-device-dialog";
|
||||||
import { getServerSession } from "next-auth";
|
|
||||||
import { redirect } from "next/navigation";
|
|
||||||
import { Suspense } from "react";
|
|
||||||
import DevicesTableSkeleton from "./device-table-skeleton";
|
import DevicesTableSkeleton from "./device-table-skeleton";
|
||||||
|
|
||||||
export default async function Devices({
|
export default async function Devices({
|
||||||
@@ -18,7 +17,6 @@ export default async function Devices({
|
|||||||
const query = (await searchParams)?.query || "";
|
const query = (await searchParams)?.query || "";
|
||||||
const page = (await searchParams)?.page || 1;
|
const page = (await searchParams)?.page || 1;
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
if (session?.user?.is_admin) return redirect("/user-devices");
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="flex justify-between items-center border rounded-md border-dashed font-bold title-bg py-4 px-2 mb-4">
|
<div className="flex justify-between items-center border rounded-md border-dashed font-bold title-bg py-4 px-2 mb-4">
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
|
import { Suspense } from "react";
|
||||||
import { DevicesTable } from "@/components/devices-table";
|
import { DevicesTable } from "@/components/devices-table";
|
||||||
import Search from "@/components/search";
|
import Search from "@/components/search";
|
||||||
import { Suspense } from "react";
|
|
||||||
|
|
||||||
export default async function ParentalControl({
|
export default async function ParentalControl({
|
||||||
searchParams,
|
searchParams,
|
||||||
}: {
|
}: {
|
||||||
searchParams: Promise<{
|
searchParams: Promise<{
|
||||||
query: string;
|
|
||||||
page: number;
|
page: number;
|
||||||
sortBy: string;
|
sortBy: string;
|
||||||
status: string;
|
status: string;
|
||||||
}>;
|
}>;
|
||||||
}) {
|
}) {
|
||||||
const query = (await searchParams)?.query || "";
|
|
||||||
|
const parentalControlFilters = {
|
||||||
|
is_active: "true",
|
||||||
|
has_a_pending_payment: "false",
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="flex justify-between items-center border rounded-md border-dashed font-bold title-bg py-4 px-2 mb-4">
|
<div className="flex justify-between items-center border rounded-md border-dashed font-bold title-bg py-4 px-2 mb-4">
|
||||||
@@ -25,10 +29,11 @@ export default async function ParentalControl({
|
|||||||
>
|
>
|
||||||
<Search />
|
<Search />
|
||||||
</div>
|
</div>
|
||||||
<Suspense key={query} fallback={"loading...."}>
|
<Suspense key={(await searchParams).page} fallback={"loading...."}>
|
||||||
<DevicesTable
|
<DevicesTable
|
||||||
parentalControl={true}
|
parentalControl={true}
|
||||||
searchParams={searchParams}
|
searchParams={searchParams}
|
||||||
|
additionalFilters={parentalControlFilters}
|
||||||
/>
|
/>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
|
import { redirect } from "next/navigation";
|
||||||
import { getPayment, getProfile } from "@/actions/payment";
|
import { getPayment, getProfile } from "@/actions/payment";
|
||||||
import CancelPaymentButton from "@/components/billing/cancel-payment-button";
|
import CancelPaymentButton from "@/components/billing/cancel-payment-button";
|
||||||
|
import ExpiryCountDown from "@/components/billing/expiry-time-countdown";
|
||||||
import ClientErrorMessage from "@/components/client-error-message";
|
import ClientErrorMessage from "@/components/client-error-message";
|
||||||
import DevicesToPay from "@/components/devices-to-pay";
|
import DevicesToPay from "@/components/devices-to-pay";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { tryCatch } from "@/utils/tryCatch";
|
import { tryCatch } from "@/utils/tryCatch";
|
||||||
import { redirect } from "next/navigation";
|
|
||||||
export default async function PaymentPage({
|
export default async function PaymentPage({
|
||||||
params,
|
params,
|
||||||
}: {
|
}: {
|
||||||
@@ -40,13 +41,24 @@ export default async function PaymentPage({
|
|||||||
{payment?.paid ? "Paid" : "Pending"}
|
{payment?.paid ? "Paid" : "Pending"}
|
||||||
</Button>
|
</Button>
|
||||||
{!payment.paid && (
|
{!payment.paid && (
|
||||||
<CancelPaymentButton paymentId={paymentId} />
|
payment.is_expired ? (
|
||||||
|
<Button
|
||||||
|
disabled
|
||||||
|
className="rounded-md opacity-100! uppercase font-semibold text-red-500 bg-red-500/20"
|
||||||
|
>
|
||||||
|
Payment Expired
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<CancelPaymentButton paymentId={paymentId} />
|
||||||
|
)
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{!payment.paid && (
|
||||||
|
<ExpiryCountDown expiryLabel="Payment" expiresAt={payment.expires_at} />
|
||||||
|
)}
|
||||||
<div
|
<div
|
||||||
id="user-filters"
|
id="user-device-payments"
|
||||||
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"
|
||||||
>
|
>
|
||||||
<DevicesToPay
|
<DevicesToPay
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import { authOptions } from "@/app/auth";
|
|
||||||
import { PaymentsTable } from "@/components/payments-table";
|
|
||||||
import Search from "@/components/search";
|
|
||||||
import { getServerSession } from "next-auth";
|
|
||||||
import { redirect } from "next/navigation";
|
|
||||||
import { Suspense } from "react";
|
import { Suspense } from "react";
|
||||||
|
import DynamicFilter from "@/components/generic-filter";
|
||||||
|
import { PaymentsTable } from "@/components/payments-table";
|
||||||
|
|
||||||
export default async function Payments({
|
export default async function Payments({
|
||||||
searchParams,
|
searchParams,
|
||||||
@@ -11,15 +8,10 @@ export default async function Payments({
|
|||||||
searchParams: Promise<{
|
searchParams: Promise<{
|
||||||
query: string;
|
query: string;
|
||||||
page: number;
|
page: number;
|
||||||
sortBy: string;
|
|
||||||
status: string;
|
|
||||||
}>;
|
}>;
|
||||||
}) {
|
}) {
|
||||||
const query = (await searchParams)?.query || "";
|
const query = (await searchParams)?.query || "";
|
||||||
const session = await getServerSession(authOptions);
|
|
||||||
if (session?.user?.is_admin) {
|
|
||||||
return redirect("/user-payments");
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="flex justify-between items-center border rounded-md border-dashed font-bold title-bg py-4 px-2 mb-4">
|
<div className="flex justify-between items-center border rounded-md border-dashed font-bold title-bg py-4 px-2 mb-4">
|
||||||
@@ -29,7 +21,56 @@ export default async function Payments({
|
|||||||
id="user-filters"
|
id="user-filters"
|
||||||
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"
|
||||||
>
|
>
|
||||||
<Search />
|
<DynamicFilter
|
||||||
|
inputs={[
|
||||||
|
{
|
||||||
|
label: "Payment",
|
||||||
|
name: "paid",
|
||||||
|
type: "radio-group",
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: "All",
|
||||||
|
value: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Paid",
|
||||||
|
value: "true",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Unpaid",
|
||||||
|
value: "false",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Payment Method",
|
||||||
|
name: "method",
|
||||||
|
type: "radio-group",
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: "All",
|
||||||
|
value: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Transfer",
|
||||||
|
value: "TRANSFER",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Wallet",
|
||||||
|
value: "WALLET",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Number of months",
|
||||||
|
name: "number_of_months",
|
||||||
|
type: "dual-range-slider",
|
||||||
|
min: 1,
|
||||||
|
max: 12,
|
||||||
|
step: 1,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>{" "}
|
||||||
</div>
|
</div>
|
||||||
<Suspense key={query} fallback={"loading...."}>
|
<Suspense key={query} fallback={"loading...."}>
|
||||||
<PaymentsTable searchParams={searchParams} />
|
<PaymentsTable searchParams={searchParams} />
|
||||||
|
|||||||
72
app/(dashboard)/top-ups/[topupId]/page.tsx
Normal file
72
app/(dashboard)/top-ups/[topupId]/page.tsx
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import { getTopup } from "@/actions/payment";
|
||||||
|
import CancelTopupButton from "@/components/billing/cancel-topup-button";
|
||||||
|
import ExpiryCountDown from "@/components/billing/expiry-time-countdown";
|
||||||
|
import ClientErrorMessage from "@/components/client-error-message";
|
||||||
|
import TopupToPay from "@/components/topup-to-pay";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { TextShimmer } from "@/components/ui/text-shimmer";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { tryCatch } from "@/utils/tryCatch";
|
||||||
|
export default async function TopupPage({
|
||||||
|
params,
|
||||||
|
}: {
|
||||||
|
params: Promise<{ topupId: string }>;
|
||||||
|
}) {
|
||||||
|
const topupId = (await params).topupId;
|
||||||
|
const [error, topup] = await tryCatch(getTopup({ id: topupId }));
|
||||||
|
if (error) {
|
||||||
|
if (error.message === "Invalid token.") redirect("/auth/signin");
|
||||||
|
return <ClientErrorMessage message={error.message} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<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">
|
||||||
|
<h3 className="text-sarLinkOrange text-2xl">Topup</h3>
|
||||||
|
<div className="flex flex-col gap-4 items-end w-full">
|
||||||
|
{!topup.is_expired && (
|
||||||
|
|
||||||
|
<Button
|
||||||
|
disabled
|
||||||
|
className={cn(
|
||||||
|
"rounded-md opacity-100! uppercase font-semibold",
|
||||||
|
// topup?.paid
|
||||||
|
// ? "text-green-900 bg-green-500/20"
|
||||||
|
// : "text-inherit bg-yellow-400",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{topup?.paid ? <span>Paid</span> : <TextShimmer>Payment Pending</TextShimmer>}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!topup.paid && (
|
||||||
|
topup.is_expired ? (
|
||||||
|
<Button
|
||||||
|
disabled
|
||||||
|
className="rounded-md opacity-100! uppercase font-semibold text-red-500 bg-red-500/20"
|
||||||
|
>
|
||||||
|
Topup Expired
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<CancelTopupButton topupId={topupId} />
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{!topup.paid && (
|
||||||
|
<ExpiryCountDown expiryLabel="Top up" expiresAt={topup.expires_at} />
|
||||||
|
)}
|
||||||
|
<div
|
||||||
|
id="user-topup-details"
|
||||||
|
className="pb-4 gap-4 flex sm:flex-row flex-col items-start justify-start"
|
||||||
|
>
|
||||||
|
<TopupToPay
|
||||||
|
disabled={topup.paid || topup.is_expired}
|
||||||
|
topup={topup || undefined}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
86
app/(dashboard)/top-ups/page.tsx
Normal file
86
app/(dashboard)/top-ups/page.tsx
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
import { Suspense } from "react";
|
||||||
|
import DynamicFilter from "@/components/generic-filter";
|
||||||
|
import { TopupsTable } from "@/components/topups-table";
|
||||||
|
|
||||||
|
export default async function Topups({
|
||||||
|
searchParams,
|
||||||
|
}: {
|
||||||
|
searchParams: Promise<{
|
||||||
|
query: string;
|
||||||
|
page: number;
|
||||||
|
sortBy: string;
|
||||||
|
status: string;
|
||||||
|
}>;
|
||||||
|
}) {
|
||||||
|
const query = (await searchParams)?.query || "";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div className="flex justify-between items-center border rounded-md border-dashed font-bold title-bg py-4 px-2 mb-4">
|
||||||
|
<h3 className="text-sarLinkOrange text-2xl">My Topups</h3>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
id="topup-filters"
|
||||||
|
className=" pb-4 gap-4 flex sm:flex-row flex-col items-start justify-start"
|
||||||
|
>
|
||||||
|
<DynamicFilter
|
||||||
|
inputs={[
|
||||||
|
{
|
||||||
|
label: "Status",
|
||||||
|
name: "status",
|
||||||
|
type: "radio-group",
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: "All",
|
||||||
|
value: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Pending",
|
||||||
|
value: "PENDING",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Cancelled",
|
||||||
|
value: "CANCELLED",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Paid",
|
||||||
|
value: "PAID",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Topup Expiry",
|
||||||
|
name: "is_expired",
|
||||||
|
type: "radio-group",
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: "All",
|
||||||
|
value: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Expired",
|
||||||
|
value: "true",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Not Expired",
|
||||||
|
value: "false",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Topup Amount",
|
||||||
|
name: "amount",
|
||||||
|
type: "dual-range-slider",
|
||||||
|
min: 0,
|
||||||
|
max: 1000,
|
||||||
|
step: 10,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<Suspense key={query} fallback={"loading...."}>
|
||||||
|
<TopupsTable searchParams={searchParams} />
|
||||||
|
</Suspense>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import { AdminDevicesTable } from "@/components/admin/admin-devices-table";
|
import { redirect } from "next/navigation";
|
||||||
import Search from "@/components/search";
|
import { getServerSession } from "next-auth";
|
||||||
import { Suspense } from "react";
|
import { Suspense } from "react";
|
||||||
|
import { authOptions } from "@/app/auth";
|
||||||
|
import { AdminDevicesTable } from "@/components/admin/admin-devices-table";
|
||||||
|
import DynamicFilter from "@/components/generic-filter";
|
||||||
|
|
||||||
export default async function UserDevices({
|
export default async function UserDevices({
|
||||||
searchParams,
|
searchParams,
|
||||||
@@ -16,20 +16,48 @@ export default async function UserDevices({
|
|||||||
}>;
|
}>;
|
||||||
}) {
|
}) {
|
||||||
const query = (await searchParams)?.query || "";
|
const query = (await searchParams)?.query || "";
|
||||||
|
const session = await getServerSession(authOptions);
|
||||||
|
if (session?.user?.is_admin !== true) redirect("/devices?page=1");
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="flex justify-between items-center border rounded-md border-dashed font-bold title-bg py-4 px-2 mb-4">
|
<div className="flex justify-between items-center border rounded-md border-dashed font-bold title-bg py-4 px-2 mb-4">
|
||||||
<h3 className="text-sarLinkOrange text-2xl">
|
<h3 className="text-sarLinkOrange text-2xl">User Devices</h3>
|
||||||
User Devices
|
|
||||||
</h3>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
id="user-filters"
|
id="user-filters"
|
||||||
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"
|
||||||
>
|
>
|
||||||
<Search />
|
<DynamicFilter
|
||||||
|
description="Filter devices by name, MAC address, or vendor."
|
||||||
|
title="Device Filter"
|
||||||
|
inputs={[
|
||||||
|
{
|
||||||
|
name: "name",
|
||||||
|
label: "Device Name",
|
||||||
|
type: "string",
|
||||||
|
placeholder: "Enter device name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "mac",
|
||||||
|
label: "MAC Address",
|
||||||
|
type: "string",
|
||||||
|
placeholder: "Enter device MAC address",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "vendor",
|
||||||
|
label: "Vendor",
|
||||||
|
type: "string",
|
||||||
|
placeholder: "Enter device vendor name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "user",
|
||||||
|
label: "Device User",
|
||||||
|
type: "string",
|
||||||
|
placeholder: "User name or id card",
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Suspense key={query} fallback={"loading...."}>
|
<Suspense key={query} fallback={"loading...."}>
|
||||||
<AdminDevicesTable parentalControl={true} searchParams={searchParams} />
|
<AdminDevicesTable parentalControl={true} searchParams={searchParams} />
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import { authOptions } from "@/app/auth";
|
import { Suspense } from "react";
|
||||||
import { UsersPaymentsTable } from "@/components/admin/user-payments-table";
|
import { UsersPaymentsTable } from "@/components/admin/user-payments-table";
|
||||||
import { getServerSession } from "next-auth";
|
|
||||||
import React, { Suspense } from "react";
|
|
||||||
|
|
||||||
export default async function UserPayments({
|
export default async function UserPayments({
|
||||||
searchParams,
|
searchParams,
|
||||||
@@ -14,13 +12,12 @@ export default async function UserPayments({
|
|||||||
}>;
|
}>;
|
||||||
}) {
|
}) {
|
||||||
const query = (await searchParams)?.query || "";
|
const query = (await searchParams)?.query || "";
|
||||||
const session = await getServerSession(authOptions);
|
// const session = await getServerSession(authOptions);
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="flex justify-between items-center border rounded-md border-dashed font-bold title-bg py-4 px-2 mb-4">
|
<div className="flex justify-between items-center border rounded-md border-dashed font-bold title-bg py-4 px-2 mb-4">
|
||||||
<h3 className="text-sarLinkOrange text-2xl">User Payments</h3>
|
<h3 className="text-sarLinkOrange text-2xl">User Payments</h3>
|
||||||
</div>
|
</div>
|
||||||
<pre>{JSON.stringify(session, null, 2)}</pre>
|
|
||||||
<Suspense key={query} fallback={"loading...."}>
|
<Suspense key={query} fallback={"loading...."}>
|
||||||
<UsersPaymentsTable searchParams={searchParams} />
|
<UsersPaymentsTable searchParams={searchParams} />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
|
|||||||
@@ -1,204 +1,188 @@
|
|||||||
// import {
|
import { HandCoins } from "lucide-react";
|
||||||
// Table,
|
import Link from "next/link";
|
||||||
// TableBody,
|
import { redirect } from "next/navigation";
|
||||||
// TableCaption,
|
import { getServerSession } from "next-auth";
|
||||||
// TableCell,
|
import { authOptions } from "@/app/auth";
|
||||||
// TableFooter,
|
import {
|
||||||
// TableHead,
|
Table,
|
||||||
// TableHeader,
|
TableBody,
|
||||||
// TableRow,
|
TableCaption,
|
||||||
// } from "@/components/ui/table";
|
TableCell,
|
||||||
// import { headers } from "next/headers";
|
TableFooter,
|
||||||
// import Link from "next/link";
|
TableHead,
|
||||||
// import BlockDeviceDialog from "../block-device-dialog";
|
TableHeader,
|
||||||
// import DeviceCard from "../device-card";
|
TableRow,
|
||||||
// import Pagination from "../pagination";
|
} from "@/components/ui/table";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { getDevices } from "@/queries/devices";
|
||||||
|
import { tryCatch } from "@/utils/tryCatch";
|
||||||
|
import BlockDeviceDialog from "../block-device-dialog";
|
||||||
|
import ClientErrorMessage from "../client-error-message";
|
||||||
|
import DeviceCard from "../device-card";
|
||||||
|
import Pagination from "../pagination";
|
||||||
|
|
||||||
export async function AdminDevicesTable({
|
export async function AdminDevicesTable({
|
||||||
searchParams,
|
searchParams,
|
||||||
parentalControl,
|
parentalControl,
|
||||||
}: {
|
}: {
|
||||||
searchParams: Promise<{
|
searchParams: Promise<{
|
||||||
query: string;
|
[key: string]: unknown;
|
||||||
page: number;
|
|
||||||
sortBy: string;
|
|
||||||
}>;
|
}>;
|
||||||
parentalControl?: boolean;
|
parentalControl?: boolean;
|
||||||
}) {
|
}) {
|
||||||
console.log(parentalControl);
|
const resolvedParams = await searchParams;
|
||||||
// const session = await auth.api.getSession({
|
const session = await getServerSession(authOptions);
|
||||||
// headers: await headers(),
|
const isAdmin = session?.user?.is_superuser;
|
||||||
// });
|
|
||||||
// const isAdmin = session?.user.role === "ADMIN";
|
|
||||||
const query = (await searchParams)?.query || "";
|
|
||||||
const page = (await searchParams)?.page;
|
|
||||||
console.log(query, page);
|
|
||||||
// const sortBy = (await searchParams)?.sortBy || "asc";
|
|
||||||
// const totalDevices = await prisma.device.count({
|
|
||||||
// where: {
|
|
||||||
// OR: [
|
|
||||||
// {
|
|
||||||
// name: {
|
|
||||||
// contains: query || "",
|
|
||||||
// mode: "insensitive",
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// mac: {
|
|
||||||
// contains: query || "",
|
|
||||||
// mode: "insensitive",
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// ],
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
|
|
||||||
// const totalPages = Math.ceil(totalDevices / 10);
|
const page = Number.parseInt(resolvedParams.page as string) || 1;
|
||||||
// const limit = 10;
|
const limit = 10;
|
||||||
// const offset = (Number(page) - 1) * limit || 0;
|
const offset = (page - 1) * limit;
|
||||||
|
|
||||||
// const devices = await prisma.device.findMany({
|
// Build params object for getDevices
|
||||||
// where: {
|
const apiParams: Record<string, string | number | undefined> = {};
|
||||||
// OR: [
|
for (const [key, value] of Object.entries(resolvedParams)) {
|
||||||
// {
|
if (value !== undefined && value !== "") {
|
||||||
// name: {
|
apiParams[key] = typeof value === "number" ? value : String(value);
|
||||||
// contains: query || "",
|
}
|
||||||
// mode: "insensitive",
|
}
|
||||||
// },
|
apiParams.limit = limit;
|
||||||
// },
|
apiParams.offset = offset;
|
||||||
// {
|
|
||||||
// mac: {
|
|
||||||
// contains: query || "",
|
|
||||||
// mode: "insensitive",
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// ],
|
|
||||||
// },
|
|
||||||
// include: {
|
|
||||||
// User: true,
|
|
||||||
// payments: true,
|
|
||||||
// },
|
|
||||||
// skip: offset,
|
|
||||||
// take: limit,
|
|
||||||
// orderBy: {
|
|
||||||
// name: `${sortBy}` as "asc" | "desc",
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
return null;
|
|
||||||
// return (
|
|
||||||
// <div>
|
|
||||||
// {devices.length === 0 ? (
|
|
||||||
// <div className="h-[calc(100svh-400px)] flex flex-col items-center justify-center my-4">
|
|
||||||
// <h3>No devices yet.</h3>
|
|
||||||
// </div>
|
|
||||||
// ) : (
|
|
||||||
// <>
|
|
||||||
// <div className="hidden sm:block">
|
|
||||||
// <Table className="overflow-scroll">
|
|
||||||
// <TableCaption>Table of all devices.</TableCaption>
|
|
||||||
// <TableHeader>
|
|
||||||
// <TableRow>
|
|
||||||
// <TableHead>Device Name</TableHead>
|
|
||||||
// <TableHead>User</TableHead>
|
|
||||||
// <TableHead>MAC Address</TableHead>
|
|
||||||
// <TableHead>isActive</TableHead>
|
|
||||||
// <TableHead>blocked</TableHead>
|
|
||||||
// <TableHead>blockedBy</TableHead>
|
|
||||||
// <TableHead>expiryDate</TableHead>
|
|
||||||
// </TableRow>
|
|
||||||
// </TableHeader>
|
|
||||||
// <TableBody className="overflow-scroll">
|
|
||||||
// {devices.map((device) => (
|
|
||||||
// <TableRow key={device.id}>
|
|
||||||
// <TableCell>
|
|
||||||
// <div className="flex flex-col items-start">
|
|
||||||
// <Link
|
|
||||||
// className="font-medium hover:underline"
|
|
||||||
// href={`/devices/${device.id}`}
|
|
||||||
// >
|
|
||||||
// {device.name}
|
|
||||||
// </Link>
|
|
||||||
// {device.isActive && (
|
|
||||||
// <span className="text-muted-foreground">
|
|
||||||
// Active until{" "}
|
|
||||||
// {new Date().toLocaleDateString("en-US", {
|
|
||||||
// month: "short",
|
|
||||||
// day: "2-digit",
|
|
||||||
// year: "numeric",
|
|
||||||
// })}
|
|
||||||
// </span>
|
|
||||||
// )}
|
|
||||||
|
|
||||||
// {device.blocked && (
|
const [error, devices] = await tryCatch(
|
||||||
// <div className="p-2 rounded border my-2">
|
getDevices(apiParams, true),
|
||||||
// <span>Comment: </span>
|
);
|
||||||
// <p className="text-neutral-500">
|
if (error) {
|
||||||
// blocked because he was watching youtube
|
if (error.message === "UNAUTHORIZED") {
|
||||||
// </p>
|
redirect("/auth/signin");
|
||||||
// </div>
|
} else {
|
||||||
// )}
|
return <ClientErrorMessage message={error.message} />;
|
||||||
// </div>
|
}
|
||||||
// </TableCell>
|
}
|
||||||
// <TableCell className="font-medium">
|
const { meta, data } = devices;
|
||||||
// {device.User?.name}
|
return (
|
||||||
// </TableCell>
|
<div>
|
||||||
|
{data?.length === 0 ? (
|
||||||
|
<div className="h-[calc(100svh-400px)] text-muted-foreground flex flex-col items-center justify-center my-4">
|
||||||
|
<h3>No devices.</h3>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div className="hidden sm:block">
|
||||||
|
<Table className="overflow-scroll">
|
||||||
|
<TableCaption>Table of all devices.</TableCaption>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>Device Name</TableHead>
|
||||||
|
<TableHead>User</TableHead>
|
||||||
|
<TableHead>MAC Address</TableHead>
|
||||||
|
<TableHead>Vendor</TableHead>
|
||||||
|
<TableHead>#</TableHead>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody className="overflow-scroll">
|
||||||
|
{data?.map((device) => (
|
||||||
|
<TableRow
|
||||||
|
key={device.id}
|
||||||
|
>
|
||||||
|
<TableCell>
|
||||||
|
<div className="flex flex-col items-start">
|
||||||
|
<Link
|
||||||
|
className={cn(
|
||||||
|
"hover:underline font-semibold",
|
||||||
|
device.is_active ? "text-green-600" : "",
|
||||||
|
)}
|
||||||
|
href={`/devices/${device.id}`}
|
||||||
|
>
|
||||||
|
{device.name}
|
||||||
|
</Link>
|
||||||
|
{device.is_active ? (
|
||||||
|
<div className="text-muted-foreground">
|
||||||
|
Active until{" "}
|
||||||
|
<span className="font-semibold">
|
||||||
|
{new Date(device.expiry_date || "").toLocaleDateString(
|
||||||
|
"en-US",
|
||||||
|
{
|
||||||
|
month: "short",
|
||||||
|
day: "2-digit",
|
||||||
|
year: "numeric",
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<p className="text-muted-foreground">Device Inactive</p>
|
||||||
|
)}
|
||||||
|
{device.has_a_pending_payment && (
|
||||||
|
<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">
|
||||||
|
Payment Pending{" "}
|
||||||
|
<HandCoins className="animate-pulse" size={14} />
|
||||||
|
</span>
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
|
|
||||||
// <TableCell className="font-medium">{device.mac}</TableCell>
|
{device.blocked_by === "ADMIN" && device.blocked && (
|
||||||
// <TableCell>
|
<div className="p-2 rounded border my-2 bg-white dark:bg-neutral-800 shadow">
|
||||||
// {device.isActive ? "Active" : "Inactive"}
|
<span className="font-semibold">Comment</span>
|
||||||
// </TableCell>
|
<p className="text-neutral-400">{device?.reason_for_blocking}</p>
|
||||||
// <TableCell>
|
</div>
|
||||||
// {device.blocked ? "Blocked" : "Not Blocked"}
|
)}
|
||||||
// </TableCell>
|
</div>
|
||||||
// <TableCell>
|
</TableCell>
|
||||||
// {device.blocked ? device.blockedBy : ""}
|
<TableCell className="font-medium">
|
||||||
// </TableCell>
|
<div className="flex flex-col items-start">
|
||||||
// <TableCell>
|
{device?.user?.name}
|
||||||
// {new Date().toLocaleDateString("en-US", {
|
<span className="text-muted-foreground">{device?.user?.id_card}</span>
|
||||||
// month: "short",
|
</div>
|
||||||
// day: "2-digit",
|
|
||||||
// year: "numeric",
|
</TableCell>
|
||||||
// })}
|
<TableCell className="font-medium">{device.mac}</TableCell>
|
||||||
// </TableCell>
|
<TableCell className="font-medium">{device?.vendor}</TableCell>
|
||||||
// <TableCell>
|
<TableCell>
|
||||||
// <BlockDeviceDialog
|
{!device.has_a_pending_payment && (
|
||||||
// admin={isAdmin}
|
<BlockDeviceDialog
|
||||||
// type={device.blocked ? "unblock" : "block"}
|
admin={isAdmin}
|
||||||
// device={device}
|
type={device.blocked ? "unblock" : "block"}
|
||||||
// />
|
device={device}
|
||||||
// </TableCell>
|
/>
|
||||||
// </TableRow>
|
)}
|
||||||
// ))}
|
</TableCell>
|
||||||
// </TableBody>
|
</TableRow>
|
||||||
// <TableFooter>
|
))}
|
||||||
// <TableRow>
|
</TableBody>
|
||||||
// <TableCell colSpan={7}>
|
<TableFooter>
|
||||||
// {query.length > 0 && (
|
<TableRow>
|
||||||
// <p className="text-sm text-muted-foreground">
|
<TableCell colSpan={5} className="text-muted-foreground">
|
||||||
// Showing {devices.length} locations for "{query}
|
{meta?.total === 1 ? (
|
||||||
// "
|
<p className="text-center">
|
||||||
// </p>
|
Total {meta?.total} device.
|
||||||
// )}
|
</p>
|
||||||
// </TableCell>
|
) : (
|
||||||
// <TableCell className="text-muted-foreground">
|
<p className="text-center">
|
||||||
// {totalDevices} devices
|
Total {meta?.total} devices.
|
||||||
// </TableCell>
|
</p>
|
||||||
// </TableRow>
|
)}
|
||||||
// </TableFooter>
|
</TableCell>
|
||||||
// </Table>
|
</TableRow>
|
||||||
// <Pagination totalPages={totalPages} currentPage={page} />
|
</TableFooter>
|
||||||
// </div>
|
</Table>
|
||||||
// <div className="sm:hidden my-4">
|
</div>
|
||||||
// {devices.map((device) => (
|
<div className="sm:hidden my-4">
|
||||||
// <DeviceCard
|
{data?.map((device) => (
|
||||||
// parentalControl={parentalControl}
|
<DeviceCard
|
||||||
// key={device.id}
|
parentalControl={parentalControl}
|
||||||
// device={device}
|
key={device.id}
|
||||||
// />
|
device={device}
|
||||||
// ))}
|
/>
|
||||||
// </div>
|
))}
|
||||||
// </>
|
</div>
|
||||||
// )}
|
<Pagination
|
||||||
// </div>
|
totalPages={meta?.last_page}
|
||||||
// );
|
currentPage={meta?.current_page}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</div >
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,19 @@
|
|||||||
import { DeviceCartDrawer } from "@/components/device-cart";
|
import { redirect } from "next/navigation";
|
||||||
import { Wallet } from "@/components/wallet";
|
import { getServerSession } from "next-auth";
|
||||||
import { NuqsAdapter } from 'nuqs/adapters/next/app'
|
import { NuqsAdapter } from 'nuqs/adapters/next/app'
|
||||||
|
|
||||||
import { ModeToggle } from "@/components/theme-toggle";
|
|
||||||
import { AppSidebar } from "@/components/ui/app-sidebar";
|
|
||||||
|
|
||||||
import { getProfile } from "@/actions/payment";
|
import { getProfile } from "@/actions/payment";
|
||||||
import { authOptions } from "@/app/auth";
|
import { authOptions } from "@/app/auth";
|
||||||
|
import { DeviceCartDrawer } from "@/components/device-cart";
|
||||||
|
import { ModeToggle } from "@/components/theme-toggle";
|
||||||
|
import { AppSidebar } from "@/components/ui/app-sidebar";
|
||||||
import { Separator } from "@/components/ui/separator";
|
import { Separator } from "@/components/ui/separator";
|
||||||
import {
|
import {
|
||||||
SidebarInset,
|
SidebarInset,
|
||||||
SidebarProvider,
|
SidebarProvider,
|
||||||
SidebarTrigger,
|
SidebarTrigger,
|
||||||
} from "@/components/ui/sidebar";
|
} from "@/components/ui/sidebar";
|
||||||
|
import { Wallet } from "@/components/wallet";
|
||||||
import { tryCatch } from "@/utils/tryCatch";
|
import { tryCatch } from "@/utils/tryCatch";
|
||||||
import { getServerSession } from "next-auth";
|
|
||||||
import { redirect } from "next/navigation";
|
|
||||||
import { WelcomeBanner } from "../welcome-banner";
|
import { WelcomeBanner } from "../welcome-banner";
|
||||||
import { AccountPopover } from "./account-popver";
|
import { AccountPopover } from "./account-popver";
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { cancelPayment } from "@/actions/payment";
|
|
||||||
import { tryCatch } from "@/utils/tryCatch";
|
|
||||||
import { Loader2, Trash2 } from "lucide-react";
|
import { Loader2, Trash2 } from "lucide-react";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
import { cancelPayment } from "@/actions/payment";
|
||||||
|
import { tryCatch } from "@/utils/tryCatch";
|
||||||
import { Button } from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
|
|
||||||
export default function CancelPaymentButton({
|
export default function CancelPaymentButton({
|
||||||
@@ -17,12 +17,16 @@ export default function CancelPaymentButton({
|
|||||||
<Button
|
<Button
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const [error, x] = await tryCatch(cancelPayment({ id: paymentId }));
|
const [error, payment] = await tryCatch(cancelPayment({ id: paymentId }));
|
||||||
console.log(x);
|
console.log(payment);
|
||||||
if (error) {
|
if (error) {
|
||||||
toast.error(error.message);
|
toast.error(error.message);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
} else {
|
} else {
|
||||||
|
toast.success("Payment cancelled successfully!", {
|
||||||
|
description: `Your payment of ${payment?.amount} MVR has been cancelled.`,
|
||||||
|
closeButton: true,
|
||||||
|
});
|
||||||
router.replace("/devices");
|
router.replace("/devices");
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|||||||
39
components/billing/cancel-topup-button.tsx
Normal file
39
components/billing/cancel-topup-button.tsx
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { Loader2, Trash2 } from "lucide-react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import React from "react";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
import { cancelTopup } from "@/actions/payment";
|
||||||
|
import { tryCatch } from "@/utils/tryCatch";
|
||||||
|
import { Button } from "../ui/button";
|
||||||
|
|
||||||
|
export default function CancelTopupButton({
|
||||||
|
topupId,
|
||||||
|
}: { topupId: string }) {
|
||||||
|
const router = useRouter();
|
||||||
|
const [loading, setLoading] = React.useState(false);
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
onClick={async () => {
|
||||||
|
setLoading(true);
|
||||||
|
const [error, topup] = await tryCatch(cancelTopup({ id: topupId }));
|
||||||
|
if (error) {
|
||||||
|
toast.error(error.message);
|
||||||
|
setLoading(false);
|
||||||
|
} else {
|
||||||
|
toast.success("Topup cancelled successfully!", {
|
||||||
|
description: `Your topup of ${topup?.amount} MVR has been cancelled.`,
|
||||||
|
closeButton: true,
|
||||||
|
})
|
||||||
|
router.replace("/top-ups");
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={loading}
|
||||||
|
variant={"destructive"}
|
||||||
|
>
|
||||||
|
Cancel Topup
|
||||||
|
{loading ? <Loader2 className="animate-spin" /> : <Trash2 />}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
57
components/billing/expiry-time-countdown.tsx
Normal file
57
components/billing/expiry-time-countdown.tsx
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
'use client'
|
||||||
|
import { usePathname, useRouter } from 'next/navigation'
|
||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { Progress } from '@/components/ui/progress'
|
||||||
|
|
||||||
|
const calculateTimeLeft = (expiresAt: string) => {
|
||||||
|
const now = Date.now()
|
||||||
|
const expirationTime = new Date(expiresAt).getTime()
|
||||||
|
return Math.max(0, Math.floor((expirationTime - now) / 1000))
|
||||||
|
}
|
||||||
|
|
||||||
|
const HumanizeTimeLeft = (seconds: number) => {
|
||||||
|
const minutes = Math.floor(seconds / 60)
|
||||||
|
const remainingSeconds = seconds % 60
|
||||||
|
return `${minutes}m ${remainingSeconds}s`
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ExpiryCountDown({ expiresAt, expiryLabel }: { expiresAt: string, expiryLabel: string }) {
|
||||||
|
const [timeLeft, setTimeLeft] = useState(calculateTimeLeft(expiresAt))
|
||||||
|
const [mounted, setMounted] = useState(false)
|
||||||
|
const router = useRouter()
|
||||||
|
const pathname = usePathname()
|
||||||
|
useEffect(() => {
|
||||||
|
setMounted(true)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const timer = setInterval(() => {
|
||||||
|
setTimeLeft(calculateTimeLeft(expiresAt))
|
||||||
|
}, 1000)
|
||||||
|
|
||||||
|
return () => clearInterval(timer)
|
||||||
|
}, [expiresAt])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (timeLeft <= 0) {
|
||||||
|
router.replace(pathname)
|
||||||
|
}
|
||||||
|
}, [timeLeft, router, pathname])
|
||||||
|
|
||||||
|
if (!mounted) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div className='overflow-clip relative mx-2 p-4 rounded-md border border-dashed flex items-center justify-between text-muted-foreground'>
|
||||||
|
<div className='absolute inset-0 title-bg mask-b-from-0' />
|
||||||
|
{timeLeft ? (
|
||||||
|
<span>Time left: {HumanizeTimeLeft(timeLeft)}</span>
|
||||||
|
) : (
|
||||||
|
<span>{expiryLabel} has expired.</span>
|
||||||
|
)}
|
||||||
|
{timeLeft > 0 && (
|
||||||
|
<Progress className='absolute bottom-0 left-0 right-0' color='#f49b5b' value={timeLeft / 600 * 100} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { blockDevice as BlockDeviceFromOmada } from "@/actions/omada-actions";
|
import { DialogDescription } from "@radix-ui/react-dialog";
|
||||||
|
import { OctagonX, ShieldBan } from "lucide-react";
|
||||||
|
import { useActionState, useEffect, useState, useTransition } from "react";
|
||||||
|
import { toast } from "sonner";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
@@ -13,168 +16,146 @@ import {
|
|||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import type { Device } from "@/lib/backend-types";
|
import type { Device } from "@/lib/backend-types";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { blockDevice } from "@/queries/devices";
|
import { blockDeviceAction } from "@/queries/devices";
|
||||||
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
|
||||||
import { OctagonX } from "lucide-react";
|
|
||||||
import { useState } from "react";
|
|
||||||
import { type SubmitHandler, useForm } from "react-hook-form";
|
|
||||||
import { toast } from "sonner";
|
|
||||||
import { z } from "zod";
|
|
||||||
import { TextShimmer } from "./ui/text-shimmer";
|
import { TextShimmer } from "./ui/text-shimmer";
|
||||||
import { Textarea } from "./ui/textarea";
|
import { Textarea } from "./ui/textarea";
|
||||||
|
|
||||||
const validationSchema = z.object({
|
export type BlockDeviceFormState = {
|
||||||
reasonForBlocking: z.string().min(5, { message: "Reason is required" }),
|
message: string;
|
||||||
});
|
success: boolean;
|
||||||
|
fieldErrors?: {
|
||||||
|
reason_for_blocking?: string[];
|
||||||
|
};
|
||||||
|
payload?: FormData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const initialState: BlockDeviceFormState = {
|
||||||
|
message: "",
|
||||||
|
success: false,
|
||||||
|
fieldErrors: {},
|
||||||
|
};
|
||||||
|
|
||||||
export default function BlockDeviceDialog({
|
export default function BlockDeviceDialog({
|
||||||
device,
|
device,
|
||||||
admin,
|
// admin,
|
||||||
}: { device: Device; type: "block" | "unblock"; admin?: boolean }) {
|
parentalControl = false,
|
||||||
const [disabled, setDisabled] = useState(false);
|
}: {
|
||||||
|
device: Device;
|
||||||
|
type: "block" | "unblock";
|
||||||
|
admin?: boolean;
|
||||||
|
parentalControl?: boolean;
|
||||||
|
}) {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const {
|
const [state, formAction, isPending] = useActionState(blockDeviceAction, initialState);
|
||||||
register,
|
const [isTransitioning, startTransition] = useTransition();
|
||||||
handleSubmit,
|
|
||||||
formState: { errors },
|
|
||||||
} = useForm<z.infer<typeof validationSchema>>({
|
|
||||||
resolver: zodResolver(validationSchema),
|
|
||||||
});
|
|
||||||
|
|
||||||
const onSubmit: SubmitHandler<z.infer<typeof validationSchema>> = (data) => {
|
const handleSimpleBlock = () => {
|
||||||
setDisabled(true);
|
startTransition(() => {
|
||||||
console.log(data);
|
const formData = new FormData();
|
||||||
toast.promise(
|
formData.append("deviceId", String(device.id));
|
||||||
blockDevice({
|
formData.append("reason_for_blocking", "");
|
||||||
deviceId: String(device.id),
|
formData.append("action", "simple-block");
|
||||||
reason_for_blocking: data.reasonForBlocking,
|
formData.append("blocked_by", "PARENT");
|
||||||
blocked_by: "ADMIN",
|
|
||||||
}),
|
formAction(formData);
|
||||||
{
|
});
|
||||||
loading: "Blocking...",
|
|
||||||
success: () => {
|
|
||||||
setDisabled(false);
|
|
||||||
setOpen((prev) => !prev);
|
|
||||||
return "Blocked!";
|
|
||||||
},
|
|
||||||
error: (error) => {
|
|
||||||
setDisabled(false);
|
|
||||||
return error || "Something went wrong";
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
setDisabled(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleUnblock = () => {
|
||||||
|
startTransition(() => {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("deviceId", String(device.id));
|
||||||
|
formData.append("reason_for_blocking", "");
|
||||||
|
formData.append("action", "unblock");
|
||||||
|
formData.append("blocked_by", "PARENT");
|
||||||
|
|
||||||
|
formAction(formData);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Show toast notifications based on state changes
|
||||||
|
useEffect(() => {
|
||||||
|
if (state.message) {
|
||||||
|
if (state.success) {
|
||||||
|
toast.success(state.message);
|
||||||
|
if (open) setOpen(false);
|
||||||
|
} else {
|
||||||
|
toast.error(state.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [state, open]);
|
||||||
|
|
||||||
|
const isLoading = isPending || isTransitioning;
|
||||||
|
|
||||||
|
// If device is blocked and user is not admin, show unblock button
|
||||||
|
if (device.blocked && parentalControl) {
|
||||||
|
return (
|
||||||
|
<Button onClick={handleUnblock} disabled={isLoading}>
|
||||||
|
{isLoading ? <TextShimmer>Unblocking</TextShimmer> : "Unblock"}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If device is not blocked and user is not admin, show simple block button
|
||||||
|
if (!device.blocked && parentalControl) {
|
||||||
|
return (
|
||||||
|
<Button onClick={handleSimpleBlock} disabled={isLoading} variant="destructive">
|
||||||
|
<ShieldBan />
|
||||||
|
{isLoading ? <TextShimmer>Blocking</TextShimmer> : "Block"}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If user is admin, show block with reason dialog
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{device.blocked ? (
|
<Dialog open={open} onOpenChange={setOpen}>
|
||||||
<Button
|
<DialogTrigger asChild>
|
||||||
onClick={() => {
|
<Button disabled={isLoading} variant="destructive">
|
||||||
setDisabled(true);
|
<OctagonX />
|
||||||
toast.promise(
|
Block
|
||||||
BlockDeviceFromOmada({
|
</Button>
|
||||||
macAddress: device.mac,
|
</DialogTrigger>
|
||||||
type: "unblock",
|
<DialogContent className="sm:max-w-[425px]">
|
||||||
reason: "",
|
<DialogHeader>
|
||||||
}),
|
<DialogTitle>Block 🚫</DialogTitle>
|
||||||
{
|
<DialogDescription className="text-sm text-muted-foreground">
|
||||||
loading: "unblockinig...",
|
Please provide a reason for blocking this device
|
||||||
success: () => {
|
</DialogDescription>
|
||||||
setDisabled(false);
|
</DialogHeader>
|
||||||
return "Unblocked!";
|
<form action={formAction} className="space-y-4">
|
||||||
},
|
<input type="hidden" name="deviceId" value={String(device.id)} />
|
||||||
error: () => {
|
<input type="hidden" name="action" value="block" />
|
||||||
setDisabled(false);
|
<input type="hidden" name="blocked_by" value="ADMIN" />
|
||||||
return "Something went wrong";
|
|
||||||
},
|
<div className="grid gap-4 py-4">
|
||||||
},
|
<div className="flex flex-col items-start gap-1">
|
||||||
);
|
<Label htmlFor="reason_for_blocking" className="text-right">
|
||||||
}}
|
Reason for blocking
|
||||||
>
|
</Label>
|
||||||
{disabled ? <TextShimmer>Unblocking</TextShimmer> : "Unblock"}
|
<Textarea
|
||||||
</Button>
|
rows={10}
|
||||||
) : (
|
name="reason_for_blocking"
|
||||||
<>
|
id="reason_for_blocking"
|
||||||
{!admin ? (
|
defaultValue={(state?.payload?.get("reason_for_blocking") || "") as string}
|
||||||
<Button
|
className={cn(
|
||||||
variant={"destructive"}
|
"col-span-5",
|
||||||
onClick={() => {
|
(state.fieldErrors?.reason_for_blocking) && "ring-2 ring-red-500",
|
||||||
setDisabled(true);
|
)}
|
||||||
toast.promise(
|
/>
|
||||||
BlockDeviceFromOmada({
|
<span className="text-sm text-red-500">
|
||||||
macAddress: device.mac,
|
{state.fieldErrors?.reason_for_blocking?.[0]}
|
||||||
type: "block",
|
</span>
|
||||||
reason: "",
|
</div>
|
||||||
blockedBy: "PARENT",
|
</div>
|
||||||
}),
|
<DialogFooter>
|
||||||
{
|
<Button variant="destructive" disabled={isLoading} type="submit">
|
||||||
loading: "blocking...",
|
{isLoading ? "Blocking..." : "Block"}
|
||||||
success: () => {
|
</Button>
|
||||||
setDisabled(false);
|
</DialogFooter>
|
||||||
return "blocked!";
|
</form>
|
||||||
},
|
</DialogContent>
|
||||||
error: () => {
|
</Dialog>
|
||||||
setDisabled(false);
|
|
||||||
return "Something went wrong";
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<OctagonX />
|
|
||||||
{disabled ? <TextShimmer>Blocking</TextShimmer> : "Block"}
|
|
||||||
</Button>
|
|
||||||
) : (
|
|
||||||
<Dialog open={open} onOpenChange={setOpen}>
|
|
||||||
<DialogTrigger asChild>
|
|
||||||
<Button disabled={disabled} variant="destructive">
|
|
||||||
<OctagonX />
|
|
||||||
Block
|
|
||||||
</Button>
|
|
||||||
</DialogTrigger>
|
|
||||||
<DialogContent className="sm:max-w-[425px]">
|
|
||||||
<DialogHeader>
|
|
||||||
<DialogTitle>
|
|
||||||
Please provide a reason for blocking this device.
|
|
||||||
</DialogTitle>
|
|
||||||
</DialogHeader>
|
|
||||||
<form onSubmit={handleSubmit(onSubmit)}>
|
|
||||||
<div className="grid gap-4 py-4">
|
|
||||||
<div className="flex flex-col items-start gap-1">
|
|
||||||
<Label htmlFor="reason" className="text-right">
|
|
||||||
Reason for blocking
|
|
||||||
</Label>
|
|
||||||
<Textarea
|
|
||||||
rows={10}
|
|
||||||
{...register("reasonForBlocking")}
|
|
||||||
id="reasonForBlocking"
|
|
||||||
className={cn(
|
|
||||||
"col-span-5",
|
|
||||||
errors.reasonForBlocking && "ring-2 ring-red-500",
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<span className="text-sm text-red-500">
|
|
||||||
{errors.reasonForBlocking?.message}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<DialogFooter>
|
|
||||||
<Button
|
|
||||||
variant={"destructive"}
|
|
||||||
disabled={disabled}
|
|
||||||
type="submit"
|
|
||||||
>
|
|
||||||
Block
|
|
||||||
</Button>
|
|
||||||
</DialogFooter>
|
|
||||||
</form>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
import { useAtom } from "jotai";
|
||||||
|
import { HandCoins } from "lucide-react";
|
||||||
|
import Link from "next/link";
|
||||||
import { TableCell, TableRow } from "@/components/ui/table";
|
import { TableCell, TableRow } from "@/components/ui/table";
|
||||||
import { deviceCartAtom } from "@/lib/atoms";
|
import { deviceCartAtom } from "@/lib/atoms";
|
||||||
import type { Device } from "@/lib/backend-types";
|
import type { Device } from "@/lib/backend-types";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { useAtom } from "jotai";
|
|
||||||
import { HandCoins } from "lucide-react";
|
|
||||||
import Link from "next/link";
|
|
||||||
import AddDevicesToCartButton from "./add-devices-to-cart-button";
|
import AddDevicesToCartButton from "./add-devices-to-cart-button";
|
||||||
import BlockDeviceDialog from "./block-device-dialog";
|
import BlockDeviceDialog from "./block-device-dialog";
|
||||||
export default function ClickableRow({
|
export default function ClickableRow({
|
||||||
@@ -66,7 +66,7 @@ export default function ClickableRow({
|
|||||||
)}
|
)}
|
||||||
{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 text-yellow-600">
|
<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>
|
||||||
@@ -91,6 +91,7 @@ export default function ClickableRow({
|
|||||||
admin={admin}
|
admin={admin}
|
||||||
type={device.blocked ? "unblock" : "block"}
|
type={device.blocked ? "unblock" : "block"}
|
||||||
device={device}
|
device={device}
|
||||||
|
parentalControl={parentalControl}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { deviceCartAtom } from "@/lib/atoms";
|
|
||||||
import type { Device } from "@/lib/backend-types";
|
|
||||||
import { cn } from "@/lib/utils";
|
|
||||||
import { useAtom } from "jotai";
|
import { useAtom } from "jotai";
|
||||||
import { HandCoins } from "lucide-react";
|
import { HandCoins } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { deviceCartAtom } from "@/lib/atoms";
|
||||||
|
import type { Device } from "@/lib/backend-types";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
import AddDevicesToCartButton from "./add-devices-to-cart-button";
|
import AddDevicesToCartButton from "./add-devices-to-cart-button";
|
||||||
import BlockDeviceDialog from "./block-device-dialog";
|
import BlockDeviceDialog from "./block-device-dialog";
|
||||||
import { Badge } from "./ui/badge";
|
import { Badge } from "./ui/badge";
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import { getServerSession } from "next-auth";
|
||||||
import { authOptions } from "@/app/auth";
|
import { authOptions } from "@/app/auth";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
@@ -11,8 +13,6 @@ import {
|
|||||||
} 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";
|
||||||
import { getServerSession } from "next-auth";
|
|
||||||
import { redirect } from "next/navigation";
|
|
||||||
import ClickableRow from "./clickable-row";
|
import ClickableRow from "./clickable-row";
|
||||||
import ClientErrorMessage from "./client-error-message";
|
import ClientErrorMessage from "./client-error-message";
|
||||||
import DeviceCard from "./device-card";
|
import DeviceCard from "./device-card";
|
||||||
@@ -21,15 +21,17 @@ import Pagination from "./pagination";
|
|||||||
export async function DevicesTable({
|
export async function DevicesTable({
|
||||||
searchParams,
|
searchParams,
|
||||||
parentalControl,
|
parentalControl,
|
||||||
|
additionalFilters = {},
|
||||||
}: {
|
}: {
|
||||||
searchParams: Promise<{
|
searchParams: Promise<{
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
}>;
|
}>;
|
||||||
parentalControl?: boolean;
|
parentalControl?: 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_superuser;
|
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;
|
||||||
@@ -42,9 +44,15 @@ export async function DevicesTable({
|
|||||||
apiParams[key] = typeof value === "number" ? value : String(value);
|
apiParams[key] = typeof value === "number" ? value : String(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(additionalFilters)) {
|
||||||
|
if (value !== undefined && value !== "") {
|
||||||
|
apiParams[key] = typeof value === "number" ? value : String(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
apiParams.limit = limit;
|
apiParams.limit = limit;
|
||||||
apiParams.offset = offset;
|
apiParams.offset = offset;
|
||||||
|
console.log("API Params:", apiParams);
|
||||||
const [error, devices] = await tryCatch(
|
const [error, devices] = await tryCatch(
|
||||||
getDevices(apiParams),
|
getDevices(apiParams),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,14 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { verifyPayment } from "@/actions/payment";
|
import {
|
||||||
|
BadgeDollarSign,
|
||||||
|
Clipboard,
|
||||||
|
ClipboardCheck,
|
||||||
|
Loader2,
|
||||||
|
Wallet,
|
||||||
|
} from "lucide-react";
|
||||||
|
import { useActionState, useEffect, useState } from "react";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
import { type VerifyDevicePaymentState, verifyDevicePayment } from "@/actions/payment";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
@@ -10,24 +19,34 @@ import {
|
|||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import type { Payment } from "@/lib/backend-types";
|
import type { Payment } from "@/lib/backend-types";
|
||||||
import type { User } from "@/lib/types/user";
|
import type { User } from "@/lib/types/user";
|
||||||
import {
|
|
||||||
BadgeDollarSign,
|
|
||||||
Clipboard,
|
|
||||||
ClipboardCheck,
|
|
||||||
Loader2,
|
|
||||||
Wallet,
|
|
||||||
} from "lucide-react";
|
|
||||||
import { useState } from "react";
|
|
||||||
import { toast } from "sonner";
|
|
||||||
import { Button } from "./ui/button";
|
import { Button } from "./ui/button";
|
||||||
|
|
||||||
|
const initialState: VerifyDevicePaymentState = {
|
||||||
|
message: "",
|
||||||
|
success: false,
|
||||||
|
fieldErrors: {},
|
||||||
|
};
|
||||||
|
|
||||||
export default function DevicesToPay({
|
export default function DevicesToPay({
|
||||||
payment,
|
payment,
|
||||||
user,
|
user,
|
||||||
}: { payment?: Payment; user?: User }) {
|
}: { payment?: Payment; user?: User }) {
|
||||||
const [verifyingWalletPayment, setVerifyingWalletPayment] = useState(false);
|
const [state, formAction, isPending] = useActionState(verifyDevicePayment, initialState);
|
||||||
const [verifyingTransferPayment, setVerifyingTransferPayment] = useState(false);
|
|
||||||
|
|
||||||
|
// Handle toast notifications based on state changes
|
||||||
|
useEffect(() => {
|
||||||
|
if (state.success && state.message) {
|
||||||
|
toast.success("Payment successful!", {
|
||||||
|
closeButton: true,
|
||||||
|
description: state.message,
|
||||||
|
});
|
||||||
|
} else if (!state.success && state.message && state.message !== initialState.message) {
|
||||||
|
toast.error("Payment Verification Failed", {
|
||||||
|
closeButton: true,
|
||||||
|
description: state.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [state]);
|
||||||
|
|
||||||
const devices = payment?.devices;
|
const devices = payment?.devices;
|
||||||
if (devices?.length === 0) {
|
if (devices?.length === 0) {
|
||||||
@@ -81,53 +100,37 @@ export default function DevicesToPay({
|
|||||||
) : (
|
) : (
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
{isWalletPayVisible && (
|
{isWalletPayVisible && (
|
||||||
<Button
|
<form action={formAction}>
|
||||||
disabled={verifyingWalletPayment || verifyingTransferPayment}
|
<input type="hidden" name="paymentId" value={payment?.id ?? ""} />
|
||||||
onClick={async () => {
|
<input type="hidden" name="method" value="WALLET" />
|
||||||
setVerifyingWalletPayment(true);
|
<Button
|
||||||
await verifyPayment({
|
disabled={isPending}
|
||||||
method: "WALLET",
|
type="submit"
|
||||||
id: payment?.id ?? "",
|
variant={"secondary"}
|
||||||
});
|
size={"lg"}
|
||||||
setVerifyingWalletPayment(false);
|
>
|
||||||
}}
|
{isPending ? "Processing payment..." : "Pay with wallet"}
|
||||||
variant={"secondary"}
|
<Wallet />
|
||||||
size={"lg"}
|
</Button>
|
||||||
>
|
</form>
|
||||||
{verifyingWalletPayment ? "Processing payment..." : "Pay with wallet"}
|
|
||||||
<Wallet />
|
|
||||||
</Button>
|
|
||||||
)}
|
)}
|
||||||
<Button
|
<form action={formAction}>
|
||||||
disabled={verifyingTransferPayment || verifyingWalletPayment}
|
<input type="hidden" name="paymentId" value={payment?.id ?? ""} />
|
||||||
onClick={async () => {
|
<input type="hidden" name="method" value="TRANSFER" />
|
||||||
setVerifyingTransferPayment(true);
|
<Button
|
||||||
try {
|
disabled={isPending}
|
||||||
await verifyPayment({
|
type="submit"
|
||||||
id: payment?.id ?? "",
|
size={"lg"}
|
||||||
method: "TRANSFER"
|
className="mb-4"
|
||||||
});
|
>
|
||||||
toast.success("Payment verification successful!");
|
{isPending ? "Processing payment..." : "I have paid"}
|
||||||
} catch (error: unknown) {
|
{isPending ? (
|
||||||
if (error instanceof Error) {
|
<Loader2 className="animate-spin" />
|
||||||
toast.error(error.message);
|
) : (
|
||||||
} else {
|
<BadgeDollarSign />
|
||||||
toast.error("Payment verification failed.");
|
)}
|
||||||
}
|
</Button>
|
||||||
} finally {
|
</form>
|
||||||
setVerifyingTransferPayment(false);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
size={"lg"}
|
|
||||||
className="mb-4"
|
|
||||||
>
|
|
||||||
{verifyingTransferPayment ? "Processing payment..." : "I have paid"}
|
|
||||||
{verifyingTransferPayment ? (
|
|
||||||
<Loader2 className="animate-spin" />
|
|
||||||
) : (
|
|
||||||
<BadgeDollarSign />
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
DrawerTitle,
|
DrawerTitle,
|
||||||
DrawerTrigger,
|
DrawerTrigger,
|
||||||
} from "@/components/ui/drawer";
|
} from "@/components/ui/drawer";
|
||||||
|
import { DualRangeSlider } from "@/components/ui/dual-range-slider";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
@@ -89,6 +90,16 @@ type FilterInputConfig<TKey extends string> =
|
|||||||
label: string;
|
label: string;
|
||||||
type: "radio-group";
|
type: "radio-group";
|
||||||
options: FilterOption[];
|
options: FilterOption[];
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
name: TKey;
|
||||||
|
label: string;
|
||||||
|
type: "dual-range-slider";
|
||||||
|
min: number;
|
||||||
|
max: number;
|
||||||
|
step?: number;
|
||||||
|
sliderLabel?: string;
|
||||||
|
formatLabel?: (value: number | undefined) => React.ReactNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Utility type to extract the config for a specific key from the array
|
// Utility type to extract the config for a specific key from the array
|
||||||
@@ -112,6 +123,8 @@ type FilterValues<
|
|||||||
? string[]
|
? string[]
|
||||||
: GetConfigForKey<K, TInputs> extends { type: "radio-group" }
|
: GetConfigForKey<K, TInputs> extends { type: "radio-group" }
|
||||||
? string
|
? string
|
||||||
|
: GetConfigForKey<K, TInputs> extends { type: "dual-range-slider" }
|
||||||
|
? number[]
|
||||||
: string;
|
: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -163,6 +176,16 @@ export default function DynamicFilter<
|
|||||||
TFilterKeys,
|
TFilterKeys,
|
||||||
TInputs
|
TInputs
|
||||||
>[typeof input.name];
|
>[typeof input.name];
|
||||||
|
} else if (input.type === "dual-range-slider") {
|
||||||
|
const minValue = searchParams.get(`${input.name}_min`);
|
||||||
|
const maxValue = searchParams.get(`${input.name}_max`);
|
||||||
|
const parsedMin = minValue ? Number(minValue) : input.min;
|
||||||
|
const parsedMax = maxValue ? Number(maxValue) : input.max;
|
||||||
|
(initialState as FilterValues<TFilterKeys, TInputs>)[input.name] =
|
||||||
|
[parsedMin, parsedMax] as FilterValues<
|
||||||
|
TFilterKeys,
|
||||||
|
TInputs
|
||||||
|
>[typeof input.name];
|
||||||
} else {
|
} else {
|
||||||
(initialState as FilterValues<TFilterKeys, TInputs>)[input.name] =
|
(initialState as FilterValues<TFilterKeys, TInputs>)[input.name] =
|
||||||
(urlValue || "") as FilterValues<
|
(urlValue || "") as FilterValues<
|
||||||
@@ -203,6 +226,15 @@ export default function DynamicFilter<
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Handler for dual range slider changes
|
||||||
|
const handleDualRangeChange =
|
||||||
|
(name: TFilterKeys) => (values: number[]) => {
|
||||||
|
setInputValues((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[name]: values,
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
// Handles applying all filters
|
// Handles applying all filters
|
||||||
const handleApplyFilters = () => {
|
const handleApplyFilters = () => {
|
||||||
const newParams = new URLSearchParams(currentParams.toString()); // Start fresh with current params
|
const newParams = new URLSearchParams(currentParams.toString()); // Start fresh with current params
|
||||||
@@ -218,6 +250,16 @@ export default function DynamicFilter<
|
|||||||
} else {
|
} else {
|
||||||
newParams.delete(input.name);
|
newParams.delete(input.name);
|
||||||
}
|
}
|
||||||
|
} else if (input.type === "dual-range-slider") {
|
||||||
|
const rangeValues = value as number[];
|
||||||
|
// Only set params if values are different from the default min/max
|
||||||
|
if (rangeValues.length === 2 && (rangeValues[0] !== input.min || rangeValues[1] !== input.max)) {
|
||||||
|
newParams.set(`${input.name}_min`, rangeValues[0].toString());
|
||||||
|
newParams.set(`${input.name}_max`, rangeValues[1].toString());
|
||||||
|
} else {
|
||||||
|
newParams.delete(`${input.name}_min`);
|
||||||
|
newParams.delete(`${input.name}_max`);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// String/Number inputs
|
// String/Number inputs
|
||||||
if (value) {
|
if (value) {
|
||||||
@@ -245,6 +287,10 @@ export default function DynamicFilter<
|
|||||||
(clearedInputState as FilterValues<TFilterKeys, TInputs>)[
|
(clearedInputState as FilterValues<TFilterKeys, TInputs>)[
|
||||||
input.name as TFilterKeys
|
input.name as TFilterKeys
|
||||||
] = [] as FilterValues<TFilterKeys, TInputs>[typeof input.name];
|
] = [] as FilterValues<TFilterKeys, TInputs>[typeof input.name];
|
||||||
|
} else if (input.type === "dual-range-slider") {
|
||||||
|
(clearedInputState as FilterValues<TFilterKeys, TInputs>)[
|
||||||
|
input.name as TFilterKeys
|
||||||
|
] = [input.min, input.max] as FilterValues<TFilterKeys, TInputs>[typeof input.name];
|
||||||
} else if (input.type === "radio-group" || input.type === "string" || input.type === "number") {
|
} else if (input.type === "radio-group" || input.type === "string" || input.type === "number") {
|
||||||
(clearedInputState as FilterValues<TFilterKeys, TInputs>)[
|
(clearedInputState as FilterValues<TFilterKeys, TInputs>)[
|
||||||
input.name as TFilterKeys
|
input.name as TFilterKeys
|
||||||
@@ -263,32 +309,50 @@ export default function DynamicFilter<
|
|||||||
const appliedFilters = useMemo(() => {
|
const appliedFilters = useMemo(() => {
|
||||||
const filters: Array<{
|
const filters: Array<{
|
||||||
key: TFilterKeys;
|
key: TFilterKeys;
|
||||||
value: string | string[];
|
value: string | string[] | number[];
|
||||||
label: string;
|
label: string;
|
||||||
config: FilterInputConfig<TFilterKeys>;
|
config: FilterInputConfig<TFilterKeys>;
|
||||||
}> = [];
|
}> = [];
|
||||||
|
|
||||||
for (const input of inputs) {
|
for (const input of inputs) {
|
||||||
const urlValue = searchParams.get(input.name);
|
if (input.type === "dual-range-slider") {
|
||||||
if (urlValue) {
|
const minValue = searchParams.get(`${input.name}_min`);
|
||||||
if (input.type === "checkbox-group") {
|
const maxValue = searchParams.get(`${input.name}_max`);
|
||||||
const deserialize = input.deserialize || defaultDeserialize;
|
if (minValue && maxValue) {
|
||||||
const deserialized = deserialize(urlValue);
|
const parsedMin = Number(minValue);
|
||||||
if (deserialized.length > 0) {
|
const parsedMax = Number(maxValue);
|
||||||
|
// Only show as applied filter if values are different from defaults
|
||||||
|
if (parsedMin !== input.min || parsedMax !== input.max) {
|
||||||
filters.push({
|
filters.push({
|
||||||
key: input.name,
|
key: input.name,
|
||||||
value: deserialized,
|
value: [parsedMin, parsedMax],
|
||||||
|
label: input.label,
|
||||||
|
config: input,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const urlValue = searchParams.get(input.name);
|
||||||
|
if (urlValue) {
|
||||||
|
if (input.type === "checkbox-group") {
|
||||||
|
const deserialize = input.deserialize || defaultDeserialize;
|
||||||
|
const deserialized = deserialize(urlValue);
|
||||||
|
if (deserialized.length > 0) {
|
||||||
|
filters.push({
|
||||||
|
key: input.name,
|
||||||
|
value: deserialized,
|
||||||
|
label: input.label,
|
||||||
|
config: input,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
filters.push({
|
||||||
|
key: input.name,
|
||||||
|
value: urlValue,
|
||||||
label: input.label,
|
label: input.label,
|
||||||
config: input,
|
config: input,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
filters.push({
|
|
||||||
key: input.name,
|
|
||||||
value: urlValue,
|
|
||||||
label: input.label,
|
|
||||||
config: input,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,7 +362,7 @@ export default function DynamicFilter<
|
|||||||
// Dynamic `prettyPrintFilter` for badges
|
// Dynamic `prettyPrintFilter` for badges
|
||||||
const prettyPrintFilter = (
|
const prettyPrintFilter = (
|
||||||
_key: TFilterKeys,
|
_key: TFilterKeys,
|
||||||
value: string | string[],
|
value: string | string[] | number[],
|
||||||
config: FilterInputConfig<TFilterKeys>,
|
config: FilterInputConfig<TFilterKeys>,
|
||||||
) => {
|
) => {
|
||||||
if (config.type === "checkbox-group") {
|
if (config.type === "checkbox-group") {
|
||||||
@@ -312,6 +376,37 @@ export default function DynamicFilter<
|
|||||||
</p>
|
</p>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (config.type === "dual-range-slider") {
|
||||||
|
const rangeValues = value as number[];
|
||||||
|
const formatLabel = config.formatLabel || ((val: number | undefined) => val?.toString() || "");
|
||||||
|
return (
|
||||||
|
<p>
|
||||||
|
{config.label}:{" "}
|
||||||
|
<span className="text-muted-foreground">
|
||||||
|
{formatLabel(rangeValues[0])} - {formatLabel(rangeValues[1])}
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (config.type === "radio-group") {
|
||||||
|
const stringValue = value as string;
|
||||||
|
// For true/false values, display the label instead of the value
|
||||||
|
if (stringValue === "true" || stringValue === "false") {
|
||||||
|
const option = config.options.find((opt) => opt.value === stringValue);
|
||||||
|
const displayValue = option?.label || stringValue;
|
||||||
|
return (
|
||||||
|
<p>
|
||||||
|
{config.label}: <span className="text-muted-foreground">{displayValue}</span>
|
||||||
|
</p>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// For other values, display as normal
|
||||||
|
return (
|
||||||
|
<p>
|
||||||
|
{config.label}: <span className="text-muted-foreground">{stringValue}</span>
|
||||||
|
</p>
|
||||||
|
);
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<p>
|
<p>
|
||||||
{config.label}: <span className="text-muted-foreground">{value}</span>
|
{config.label}: <span className="text-muted-foreground">{value}</span>
|
||||||
@@ -322,15 +417,26 @@ export default function DynamicFilter<
|
|||||||
// Handles removing an individual filter
|
// Handles removing an individual filter
|
||||||
const handleRemoveFilter = (keyToRemove: TFilterKeys) => {
|
const handleRemoveFilter = (keyToRemove: TFilterKeys) => {
|
||||||
const newParams = new URLSearchParams(currentParams.toString());
|
const newParams = new URLSearchParams(currentParams.toString());
|
||||||
newParams.delete(keyToRemove);
|
|
||||||
newParams.set("page", "1"); // Reset page after removing a filter
|
|
||||||
|
|
||||||
// Clear the specific input's local state
|
// Clear the specific input's local state
|
||||||
const inputConfig = inputs.find((input) => input.name === keyToRemove);
|
const inputConfig = inputs.find((input) => input.name === keyToRemove);
|
||||||
setInputValues((prev) => ({
|
|
||||||
...prev,
|
if (inputConfig?.type === "dual-range-slider") {
|
||||||
[keyToRemove]: inputConfig?.type === "checkbox-group" ? [] : "",
|
newParams.delete(`${keyToRemove}_min`);
|
||||||
}));
|
newParams.delete(`${keyToRemove}_max`);
|
||||||
|
setInputValues((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[keyToRemove]: [inputConfig.min, inputConfig.max],
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
newParams.delete(keyToRemove);
|
||||||
|
setInputValues((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[keyToRemove]: inputConfig?.type === "checkbox-group" ? [] : "",
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
newParams.set("page", "1"); // Reset page after removing a filter
|
||||||
|
|
||||||
startTransition(() => {
|
startTransition(() => {
|
||||||
replace(`${pathname}?${newParams.toString()}`);
|
replace(`${pathname}?${newParams.toString()}`);
|
||||||
@@ -384,6 +490,27 @@ export default function DynamicFilter<
|
|||||||
onChange={handleCheckboxGroupChange(input.name)}
|
onChange={handleCheckboxGroupChange(input.name)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
case "dual-range-slider":
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={input.name}
|
||||||
|
className="px-2 w-full flex flex-col gap-2 p-2 border rounded-md"
|
||||||
|
>
|
||||||
|
<Label className="font-semibold text-sm">
|
||||||
|
{input.label}
|
||||||
|
</Label>
|
||||||
|
<div className="px-3 py-2 mt-5">
|
||||||
|
<DualRangeSlider
|
||||||
|
label={(value) => <span className="text-xs">{value}{input.sliderLabel}</span>}
|
||||||
|
value={inputValues[input.name] as number[]}
|
||||||
|
onValueChange={handleDualRangeChange(input.name)}
|
||||||
|
min={input.min}
|
||||||
|
max={input.max}
|
||||||
|
step={input.step || 1}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
case "radio-group":
|
case "radio-group":
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -474,4 +601,4 @@ export default function DynamicFilter<
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { PhoneIcon } from "lucide-react"
|
||||||
|
import Link from "next/link"
|
||||||
import {
|
import {
|
||||||
Accordion,
|
Accordion,
|
||||||
AccordionContent,
|
AccordionContent,
|
||||||
@@ -5,8 +7,6 @@ import {
|
|||||||
AccordionTrigger,
|
AccordionTrigger,
|
||||||
} from "@/components/ui/accordion"
|
} from "@/components/ui/accordion"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import { PhoneIcon } from "lucide-react"
|
|
||||||
import Link from "next/link"
|
|
||||||
|
|
||||||
|
|
||||||
export function GetMacAccordion() {
|
export function GetMacAccordion() {
|
||||||
@@ -18,7 +18,7 @@ export function GetMacAccordion() {
|
|||||||
>
|
>
|
||||||
<AccordionItem value="item-1">
|
<AccordionItem value="item-1">
|
||||||
<AccordionTrigger>How do I find my MAC Address?</AccordionTrigger>
|
<AccordionTrigger>How do I find my MAC Address?</AccordionTrigger>
|
||||||
<AccordionContent className="flex flex-col gap-4 text-balance">
|
<AccordionContent className="flex flex-col gap-4 text-start">
|
||||||
<p>
|
<p>
|
||||||
A MAC (Media Access Control) address is a unique identifier assigned
|
A MAC (Media Access Control) address is a unique identifier assigned
|
||||||
to a device`'`s network. It is used to identify the device on a
|
to a device`'`s network. It is used to identify the device on a
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
import { Calendar } from "lucide-react";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import { getPayments } from "@/actions/payment";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
@@ -8,14 +12,9 @@ import {
|
|||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow,
|
TableRow,
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import Link from "next/link";
|
|
||||||
|
|
||||||
import { getPayments } from "@/actions/payment";
|
|
||||||
import type { Payment } from "@/lib/backend-types";
|
import type { Payment } from "@/lib/backend-types";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { tryCatch } from "@/utils/tryCatch";
|
import { tryCatch } from "@/utils/tryCatch";
|
||||||
import { Calendar } from "lucide-react";
|
|
||||||
import { redirect } from "next/navigation";
|
|
||||||
import Pagination from "./pagination";
|
import Pagination from "./pagination";
|
||||||
import { Badge } from "./ui/badge";
|
import { Badge } from "./ui/badge";
|
||||||
import { Button } from "./ui/button";
|
import { Button } from "./ui/button";
|
||||||
@@ -25,66 +24,17 @@ export async function PaymentsTable({
|
|||||||
searchParams,
|
searchParams,
|
||||||
}: {
|
}: {
|
||||||
searchParams: Promise<{
|
searchParams: Promise<{
|
||||||
query: string;
|
[key: string]: unknown;
|
||||||
page: number;
|
|
||||||
sortBy: string;
|
|
||||||
}>;
|
}>;
|
||||||
}) {
|
}) {
|
||||||
const query = (await searchParams)?.query || "";
|
const resolvedParams = await searchParams;
|
||||||
// const session = await auth.api.getSession({
|
const apiParams: Record<string, string | number | undefined> = {};
|
||||||
// headers: await headers(),
|
for (const [key, value] of Object.entries(resolvedParams)) {
|
||||||
// });
|
if (value !== undefined && value !== "") {
|
||||||
// const query = (await searchParams)?.query || "";
|
apiParams[key] = typeof value === "number" ? value : String(value);
|
||||||
// const page = (await searchParams)?.page;
|
}
|
||||||
// const totalPayments = await prisma.payment.count({
|
}
|
||||||
// where: {
|
const [error, payments] = await tryCatch(getPayments(apiParams));
|
||||||
// userId: session?.session.userId,
|
|
||||||
// OR: [
|
|
||||||
// {
|
|
||||||
// devices: {
|
|
||||||
// every: {
|
|
||||||
// name: {
|
|
||||||
// contains: query || "",
|
|
||||||
// mode: "insensitive",
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// ],
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
|
|
||||||
// const totalPages = Math.ceil(totalPayments / 10);
|
|
||||||
// const limit = 10;
|
|
||||||
// const offset = (Number(page) - 1) * limit || 0;
|
|
||||||
|
|
||||||
// const payments = await prisma.payment.findMany({
|
|
||||||
// where: {
|
|
||||||
// userId: session?.session.userId,
|
|
||||||
// OR: [
|
|
||||||
// {
|
|
||||||
// devices: {
|
|
||||||
// every: {
|
|
||||||
// name: {
|
|
||||||
// contains: query || "",
|
|
||||||
// mode: "insensitive",
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// ],
|
|
||||||
// },
|
|
||||||
// include: {
|
|
||||||
// devices: true,
|
|
||||||
// },
|
|
||||||
|
|
||||||
// skip: offset,
|
|
||||||
// take: limit,
|
|
||||||
// orderBy: {
|
|
||||||
// createdAt: "desc",
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
const [error, payments] = await tryCatch(getPayments());
|
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
if (error.message.includes("Unauthorized")) {
|
if (error.message.includes("Unauthorized")) {
|
||||||
@@ -109,7 +59,7 @@ export async function PaymentsTable({
|
|||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead>Details</TableHead>
|
<TableHead>Details</TableHead>
|
||||||
<TableHead>Duration</TableHead>
|
<TableHead>Duration</TableHead>
|
||||||
|
<TableHead>Status</TableHead>
|
||||||
<TableHead>Amount</TableHead>
|
<TableHead>Amount</TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
@@ -134,6 +84,8 @@ export async function PaymentsTable({
|
|||||||
month: "short",
|
month: "short",
|
||||||
day: "2-digit",
|
day: "2-digit",
|
||||||
year: "numeric",
|
year: "numeric",
|
||||||
|
minute: "2-digit",
|
||||||
|
hour: "2-digit",
|
||||||
},
|
},
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
@@ -148,16 +100,6 @@ export async function PaymentsTable({
|
|||||||
View Details
|
View Details
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
<Badge
|
|
||||||
className={cn(
|
|
||||||
payment?.paid
|
|
||||||
? "text-green-500 bg-green-500/20"
|
|
||||||
: "text-yellow-500 bg-yellow-500/20",
|
|
||||||
)}
|
|
||||||
variant={payment.paid ? "outline" : "secondary"}
|
|
||||||
>
|
|
||||||
{payment.paid ? "Paid" : "Unpaid"}
|
|
||||||
</Badge>
|
|
||||||
</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>
|
||||||
@@ -174,9 +116,30 @@ export async function PaymentsTable({
|
|||||||
</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>
|
||||||
|
<span className="font-semibold pr-2">
|
||||||
|
{payment.paid ? (
|
||||||
|
<Badge
|
||||||
|
className={cn(
|
||||||
|
payment.status === "PENDING"
|
||||||
|
? "bg-yellow-100 text-yellow-700 dark:bg-yellow-700 dark:text-yellow-100"
|
||||||
|
: "bg-green-100 dark:bg-green-700"
|
||||||
|
)}
|
||||||
|
variant="outline"
|
||||||
|
>
|
||||||
|
{payment.status}
|
||||||
|
</Badge>
|
||||||
|
) : payment.is_expired ? (
|
||||||
|
<Badge>Expired</Badge>
|
||||||
|
) : (
|
||||||
|
<Badge variant="outline">{payment.status}</Badge>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<span className="font-semibold pr-2">
|
<span className="font-semibold pr-2">
|
||||||
{payment.amount.toFixed(2)}
|
{payment.amount.toFixed(2)}
|
||||||
@@ -188,18 +151,17 @@ export async function PaymentsTable({
|
|||||||
</TableBody>
|
</TableBody>
|
||||||
<TableFooter>
|
<TableFooter>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell colSpan={2}>
|
|
||||||
{query.length > 0 && (
|
<TableCell colSpan={3} className="text-muted-foreground">
|
||||||
<p className="text-sm text-muted-foreground">
|
{meta?.total === 1 ? (
|
||||||
Showing {payments?.data?.length} payments for "
|
<p className="text-center">
|
||||||
{query}
|
Total {meta?.total} payment.
|
||||||
"
|
|
||||||
</p>
|
</p>
|
||||||
)}
|
) : (
|
||||||
</TableCell>
|
<p className="text-center">
|
||||||
<TableCell className="text-muted-foreground">
|
Total {meta?.total} payments.
|
||||||
{meta.total} payments
|
</p>
|
||||||
</TableCell>
|
)} </TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableFooter>
|
</TableFooter>
|
||||||
</Table>
|
</Table>
|
||||||
@@ -223,7 +185,7 @@ function MobilePaymentDetails({ payment }: { payment: Payment }) {
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex flex-col items-start border rounded p-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"
|
||||||
: "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",
|
||||||
@@ -236,6 +198,8 @@ function MobilePaymentDetails({ payment }: { payment: Payment }) {
|
|||||||
month: "short",
|
month: "short",
|
||||||
day: "2-digit",
|
day: "2-digit",
|
||||||
year: "numeric",
|
year: "numeric",
|
||||||
|
minute: "2-digit",
|
||||||
|
hour: "2-digit",
|
||||||
})}
|
})}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -249,16 +213,6 @@ function MobilePaymentDetails({ payment }: { payment: Payment }) {
|
|||||||
View Details
|
View Details
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
<Badge
|
|
||||||
className={cn(
|
|
||||||
payment?.paid
|
|
||||||
? "text-green-500 bg-green-500/20"
|
|
||||||
: "text-yellow-500 bg-yellow-500/20",
|
|
||||||
)}
|
|
||||||
variant={payment.paid ? "outline" : "secondary"}
|
|
||||||
>
|
|
||||||
{payment.paid ? "Paid" : "Unpaid"}
|
|
||||||
</Badge>
|
|
||||||
</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>
|
||||||
@@ -277,9 +231,29 @@ function MobilePaymentDetails({ payment }: { payment: Payment }) {
|
|||||||
</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>
|
||||||
<span className="text-sm text-muted-foreground">
|
<div className="flex items-center justify-between">
|
||||||
{payment.amount.toFixed(2)} MVR
|
<span className="text-sm text-muted-foreground">
|
||||||
</span>
|
{payment.amount.toFixed(2)} MVR
|
||||||
|
</span>
|
||||||
|
<span className="font-semibold pr-2">
|
||||||
|
{payment.paid ? (
|
||||||
|
<Badge
|
||||||
|
className={cn(
|
||||||
|
payment.status === "PENDING"
|
||||||
|
? "bg-yellow-100 text-yellow-700 dark:bg-yellow-700 dark:text-yellow-100"
|
||||||
|
: "bg-green-100 dark:bg-green-700"
|
||||||
|
)}
|
||||||
|
variant="outline"
|
||||||
|
>
|
||||||
|
{payment.status}
|
||||||
|
</Badge>
|
||||||
|
) : payment.is_expired ? (
|
||||||
|
<Badge>Expired</Badge>
|
||||||
|
) : (
|
||||||
|
<Badge variant="secondary">{payment.status}</Badge>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
182
components/topup-to-pay.tsx
Normal file
182
components/topup-to-pay.tsx
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
"use client";
|
||||||
|
import {
|
||||||
|
BadgeDollarSign,
|
||||||
|
Clipboard,
|
||||||
|
ClipboardCheck,
|
||||||
|
Loader2,
|
||||||
|
} from "lucide-react";
|
||||||
|
import { useActionState, useEffect, useState } from "react";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
import { type VerifyTopupPaymentState, verifyTopupPayment } from "@/actions/payment";
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCaption,
|
||||||
|
TableCell,
|
||||||
|
TableFooter,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table";
|
||||||
|
import type { Topup } from "@/lib/backend-types";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const initialState: VerifyTopupPaymentState = {
|
||||||
|
message: "",
|
||||||
|
success: false,
|
||||||
|
fieldErrors: {},
|
||||||
|
};
|
||||||
|
export default function TopupToPay({ topup, disabled }: { topup?: Topup, disabled?: boolean }) {
|
||||||
|
const [state, formAction, isPending] = useActionState(verifyTopupPayment, initialState);
|
||||||
|
|
||||||
|
// Handle toast notifications based on state changes
|
||||||
|
useEffect(() => {
|
||||||
|
if (state.success && state.message) {
|
||||||
|
toast.success("Topup successful!", {
|
||||||
|
closeButton: true,
|
||||||
|
description: state.transaction
|
||||||
|
? `Your topup payment has been verified successfully using ${state.transaction.sourceBank} bank transfer on ${state.transaction.trxDate}.`
|
||||||
|
: state.message,
|
||||||
|
});
|
||||||
|
} else if (!state.success && state.message && state.message !== initialState.message) {
|
||||||
|
toast.error("Topup Payment Verification Failed", {
|
||||||
|
closeButton: true,
|
||||||
|
description: state.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [state]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-full">
|
||||||
|
<div className="m-2 flex items-end justify-end p-2 text-sm text-foreground border rounded">
|
||||||
|
<Table>
|
||||||
|
<TableCaption>
|
||||||
|
<div className="max-w-sm mx-auto">
|
||||||
|
<p>Please send the following amount to the payment address</p>
|
||||||
|
<AccountInfomation
|
||||||
|
accName="Baraveli Dev"
|
||||||
|
accountNo="90101400028321000"
|
||||||
|
/>
|
||||||
|
{topup?.paid ? (
|
||||||
|
<Button
|
||||||
|
size={"lg"}
|
||||||
|
variant={"secondary"}
|
||||||
|
disabled
|
||||||
|
className="dark:text-green-200 text-green-900 bg-green-500/20 uppercase font-semibold"
|
||||||
|
>
|
||||||
|
Topup Payment Verified
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
<form action={formAction}>
|
||||||
|
<input type="hidden" name="topupId" value={topup?.id ?? ""} />
|
||||||
|
<Button
|
||||||
|
disabled={disabled || isPending}
|
||||||
|
type="submit"
|
||||||
|
size={"lg"}
|
||||||
|
className="mb-4"
|
||||||
|
>
|
||||||
|
{isPending
|
||||||
|
? "Processing payment..."
|
||||||
|
: "I have paid"}
|
||||||
|
{isPending ? (
|
||||||
|
<Loader2 className="animate-spin" />
|
||||||
|
) : (
|
||||||
|
<BadgeDollarSign />
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</TableCaption>
|
||||||
|
<TableBody className="">
|
||||||
|
<TableRow>
|
||||||
|
<TableCell>Topup created</TableCell>
|
||||||
|
<TableCell className="text-right text-muted-foreground">
|
||||||
|
{new Date(topup?.created_at ?? "").toLocaleDateString("en-US", {
|
||||||
|
month: "short",
|
||||||
|
day: "2-digit",
|
||||||
|
year: "numeric",
|
||||||
|
minute: "2-digit",
|
||||||
|
hour: "2-digit",
|
||||||
|
second: "2-digit",
|
||||||
|
})}
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow>
|
||||||
|
<TableCell>Payment received</TableCell>
|
||||||
|
<TableCell className="text-right text-sarLinkOrange">
|
||||||
|
{topup?.paid_at
|
||||||
|
? new Date(topup.paid_at).toLocaleDateString("en-US", {
|
||||||
|
month: "short",
|
||||||
|
day: "2-digit",
|
||||||
|
year: "numeric",
|
||||||
|
minute: "2-digit",
|
||||||
|
hour: "2-digit",
|
||||||
|
second: "2-digit",
|
||||||
|
})
|
||||||
|
: "-"}
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow>
|
||||||
|
<TableCell>MIB Reference</TableCell>
|
||||||
|
<TableCell className="text-right">
|
||||||
|
{topup?.mib_reference ? topup.mib_reference : "-"}
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
</TableBody>
|
||||||
|
<TableFooter>
|
||||||
|
<TableRow className="">
|
||||||
|
<TableCell colSpan={1}>Total Due</TableCell>
|
||||||
|
<TableCell className="text-right text-3xl font-bold">
|
||||||
|
{topup?.amount?.toFixed(2)}
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
</TableFooter>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function AccountInfomation({
|
||||||
|
accountNo,
|
||||||
|
accName,
|
||||||
|
}: {
|
||||||
|
accountNo: string;
|
||||||
|
accName: string;
|
||||||
|
}) {
|
||||||
|
const [accNo, setAccNo] = useState(false);
|
||||||
|
return (
|
||||||
|
<div className="justify-start items-start border my-4 flex flex-col gap-2 p-2 rounded-md">
|
||||||
|
<h6 className="title-bg uppercase p-2 border rounded w-full font-semibold">
|
||||||
|
Account Information
|
||||||
|
</h6>
|
||||||
|
<div className="border justify-start flex flex-col items-start bg-white/10 w-full p-2 rounded">
|
||||||
|
<div className="text-sm font-semibold">Account Name</div>
|
||||||
|
<span>{accName}</span>
|
||||||
|
</div>
|
||||||
|
<div className="border flex justify-between items-start gap-2 bg-white/10 w-full p-2 rounded">
|
||||||
|
<div className="flex flex-col items-start justify-start">
|
||||||
|
<p className="text-sm font-semibold">Account No</p>
|
||||||
|
<span>{accountNo}</span>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
setAccNo(true);
|
||||||
|
navigator.clipboard.writeText(accountNo);
|
||||||
|
}, 2000);
|
||||||
|
toast.success("Account number copied!");
|
||||||
|
setAccNo((prev) => !prev);
|
||||||
|
}}
|
||||||
|
variant={"link"}
|
||||||
|
>
|
||||||
|
{accNo ? <Clipboard /> : <ClipboardCheck color="green" />}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
216
components/topups-table.tsx
Normal file
216
components/topups-table.tsx
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
import { Calendar } from "lucide-react";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import { getTopups } from "@/actions/payment";
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCaption,
|
||||||
|
TableCell,
|
||||||
|
TableFooter,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table";
|
||||||
|
import type { Topup } from "@/lib/backend-types";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { tryCatch } from "@/utils/tryCatch";
|
||||||
|
import Pagination from "./pagination";
|
||||||
|
import { Badge } from "./ui/badge";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
|
||||||
|
export async function TopupsTable({
|
||||||
|
searchParams,
|
||||||
|
}: {
|
||||||
|
searchParams: Promise<{
|
||||||
|
[key: string]: unknown;
|
||||||
|
}>;
|
||||||
|
}) {
|
||||||
|
const resolvedParams = await searchParams;
|
||||||
|
|
||||||
|
// Build params object
|
||||||
|
const apiParams: Record<string, string | number | undefined> = {};
|
||||||
|
for (const [key, value] of Object.entries(resolvedParams)) {
|
||||||
|
if (value !== undefined && value !== "") {
|
||||||
|
apiParams[key] = typeof value === "number" ? value : String(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const [error, topups] = await tryCatch(getTopups(apiParams));
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
if (error.message.includes("Unauthorized")) {
|
||||||
|
redirect("/auth/signin");
|
||||||
|
} else {
|
||||||
|
return <pre>{JSON.stringify(error, null, 2)}</pre>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const { data, meta } = topups;
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{data?.length === 0 ? (
|
||||||
|
<div className="h-[calc(100svh-400px)] flex flex-col items-center justify-center my-4">
|
||||||
|
<h3>No topups yet.</h3>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div className="hidden sm:block">
|
||||||
|
<Table className="overflow-scroll">
|
||||||
|
<TableCaption>Table of all topups.</TableCaption>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>Details</TableHead>
|
||||||
|
<TableHead>Status</TableHead>
|
||||||
|
<TableHead>Amount</TableHead>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody className="overflow-scroll">
|
||||||
|
{topups?.data?.map((topup) => (
|
||||||
|
<TableRow key={topup.id}>
|
||||||
|
<TableCell>
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"flex flex-col items-start border rounded p-2",
|
||||||
|
topup?.paid
|
||||||
|
? "bg-green-500/10 border-dashed border-green-500"
|
||||||
|
: topup?.is_expired
|
||||||
|
? "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",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Calendar size={16} opacity={0.5} />
|
||||||
|
<span className="text-muted-foreground">
|
||||||
|
{new Date(topup.created_at).toLocaleDateString(
|
||||||
|
"en-US",
|
||||||
|
{
|
||||||
|
month: "short",
|
||||||
|
day: "2-digit",
|
||||||
|
year: "numeric",
|
||||||
|
minute: "2-digit",
|
||||||
|
hour: "2-digit",
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-2 mt-2">
|
||||||
|
<Link
|
||||||
|
className="font-medium hover:underline"
|
||||||
|
href={`/top-ups/${topup.id}`}
|
||||||
|
>
|
||||||
|
<Button size={"sm"} variant="outline">
|
||||||
|
View Details
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
|
<TableCell>
|
||||||
|
<span className="font-semibold pr-2">
|
||||||
|
{topup.paid ? (
|
||||||
|
<Badge
|
||||||
|
className="bg-green-100 dark:bg-green-700"
|
||||||
|
variant="outline"
|
||||||
|
>
|
||||||
|
{topup.status}
|
||||||
|
</Badge>
|
||||||
|
) : topup.is_expired ? (
|
||||||
|
<Badge>Expired</Badge>
|
||||||
|
) : (
|
||||||
|
<Badge variant="outline">{topup.status}</Badge>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<span className="font-semibold pr-2">
|
||||||
|
{topup.amount.toFixed(2)}
|
||||||
|
</span>
|
||||||
|
MVR
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableBody>
|
||||||
|
<TableFooter>
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={4} className="text-muted-foreground">
|
||||||
|
{meta?.total === 1 ? (
|
||||||
|
<p className="text-center">Total {meta?.total} topup.</p>
|
||||||
|
) : (
|
||||||
|
<p className="text-center">Total {meta?.total} topups.</p>
|
||||||
|
)}
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
</TableFooter>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
<div className="sm:hidden block">
|
||||||
|
{data.map((topup) => (
|
||||||
|
<MobileTopupDetails key={topup.id} topup={topup} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<Pagination
|
||||||
|
totalPages={meta.total / meta.per_page}
|
||||||
|
currentPage={meta.current_page}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function MobileTopupDetails({ topup }: { topup: Topup }) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"flex flex-col items-start border rounded p-2 my-2",
|
||||||
|
topup?.paid
|
||||||
|
? "bg-green-500/10 border-dashed border-green=500"
|
||||||
|
: "bg-yellow-500/10 border-dashed border-yellow-500 dark:border-yellow-500/50",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Calendar size={16} opacity={0.5} />
|
||||||
|
<span className="text-muted-foreground text-sm">
|
||||||
|
{new Date(topup.created_at).toLocaleDateString("en-US", {
|
||||||
|
month: "short",
|
||||||
|
day: "2-digit",
|
||||||
|
year: "numeric",
|
||||||
|
})}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-2 mt-2">
|
||||||
|
<Link
|
||||||
|
className="font-medium hover:underline"
|
||||||
|
href={`/top-ups/${topup.id}`}
|
||||||
|
>
|
||||||
|
<Button size={"sm"} variant="outline">
|
||||||
|
View Details
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<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">
|
||||||
|
<h3 className="text-sm font-medium">Amount</h3>
|
||||||
|
<span className="text-sm text-muted-foreground">
|
||||||
|
{topup.amount.toFixed(2)} MVR
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<span className="font-semibold pr-2">
|
||||||
|
{topup.paid ? (
|
||||||
|
<Badge className="bg-green-100 dark:bg-green-700" variant="outline">
|
||||||
|
{topup.status}
|
||||||
|
</Badge>
|
||||||
|
) : topup.is_expired ? (
|
||||||
|
<Badge>Expired</Badge>
|
||||||
|
) : (
|
||||||
|
<Badge variant="secondary">{topup.status}</Badge>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
BadgePlus,
|
||||||
Calculator,
|
Calculator,
|
||||||
ChevronRight,
|
ChevronRight,
|
||||||
Coins,
|
Coins,
|
||||||
@@ -9,7 +10,8 @@ import {
|
|||||||
UsersRound,
|
UsersRound,
|
||||||
Wallet2Icon,
|
Wallet2Icon,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { getServerSession } from "next-auth";
|
||||||
import { authOptions } from "@/app/auth";
|
import { authOptions } from "@/app/auth";
|
||||||
import {
|
import {
|
||||||
Collapsible,
|
Collapsible,
|
||||||
@@ -28,8 +30,6 @@ import {
|
|||||||
SidebarMenuItem,
|
SidebarMenuItem,
|
||||||
SidebarRail,
|
SidebarRail,
|
||||||
} from "@/components/ui/sidebar";
|
} from "@/components/ui/sidebar";
|
||||||
import { getServerSession } from "next-auth";
|
|
||||||
import Link from "next/link";
|
|
||||||
|
|
||||||
type Permission = {
|
type Permission = {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -40,17 +40,17 @@ type Categories = {
|
|||||||
id: string;
|
id: string;
|
||||||
children: (
|
children: (
|
||||||
| {
|
| {
|
||||||
title: string;
|
title: string;
|
||||||
link: string;
|
link: string;
|
||||||
perm_identifier: string;
|
perm_identifier: string;
|
||||||
icon: React.JSX.Element;
|
icon: React.JSX.Element;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
title: string;
|
title: string;
|
||||||
link: string;
|
link: string;
|
||||||
icon: React.JSX.Element;
|
icon: React.JSX.Element;
|
||||||
perm_identifier?: undefined;
|
perm_identifier?: undefined;
|
||||||
}
|
}
|
||||||
)[];
|
)[];
|
||||||
}[];
|
}[];
|
||||||
|
|
||||||
@@ -74,9 +74,15 @@ export async function AppSidebar({
|
|||||||
icon: <CreditCard size={16} />,
|
icon: <CreditCard size={16} />,
|
||||||
perm_identifier: "payment",
|
perm_identifier: "payment",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: "Top Ups",
|
||||||
|
link: "/top-ups?page=1",
|
||||||
|
icon: <BadgePlus size={16} />,
|
||||||
|
perm_identifier: "topup",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: "Parental Control",
|
title: "Parental Control",
|
||||||
link: "/parental-control",
|
link: "/parental-control?page=1",
|
||||||
icon: <CreditCard size={16} />,
|
icon: <CreditCard size={16} />,
|
||||||
perm_identifier: "device",
|
perm_identifier: "device",
|
||||||
},
|
},
|
||||||
@@ -128,27 +134,31 @@ export async function AppSidebar({
|
|||||||
|
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
|
|
||||||
const filteredCategories = categories.map((category) => {
|
|
||||||
const filteredChildren = category.children.filter((child) => {
|
|
||||||
const permIdentifier = child.perm_identifier;
|
|
||||||
return session?.user?.user_permissions?.some((permission: Permission) => {
|
|
||||||
const permissionParts = permission.name.split(" ");
|
|
||||||
const modelNameFromPermission = permissionParts.slice(2).join(" ");
|
|
||||||
return modelNameFromPermission === permIdentifier;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return { ...category, children: filteredChildren };
|
|
||||||
});
|
|
||||||
const filteredCategoriesWithChildren = filteredCategories.filter(
|
|
||||||
(category) => category.children.length > 0,
|
|
||||||
);
|
|
||||||
|
|
||||||
let CATEGORIES: Categories;
|
let CATEGORIES: Categories;
|
||||||
if (session?.user?.is_superuser) {
|
if (session?.user?.is_admin) {
|
||||||
CATEGORIES = categories;
|
CATEGORIES = categories;
|
||||||
} else {
|
} else {
|
||||||
CATEGORIES = filteredCategoriesWithChildren;
|
// Filter out ADMIN CONTROL category for non-admin users
|
||||||
|
const nonAdminCategories = categories.filter(
|
||||||
|
(category) => category.id !== "ADMIN CONTROL"
|
||||||
|
);
|
||||||
|
|
||||||
|
const filteredCategories = nonAdminCategories.map((category) => {
|
||||||
|
const filteredChildren = category.children.filter((child) => {
|
||||||
|
const permIdentifier = child.perm_identifier;
|
||||||
|
return session?.user?.user_permissions?.some((permission: Permission) => {
|
||||||
|
const permissionParts = permission.name.split(" ");
|
||||||
|
const modelNameFromPermission = permissionParts.slice(2).join(" ");
|
||||||
|
return modelNameFromPermission === permIdentifier;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return { ...category, children: filteredChildren };
|
||||||
|
});
|
||||||
|
|
||||||
|
CATEGORIES = filteredCategories.filter(
|
||||||
|
(category) => category.children.length > 0,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import * as React from "react"
|
|
||||||
import { Dialog as DialogPrimitive } from "radix-ui"
|
|
||||||
import { XIcon } from "lucide-react"
|
import { XIcon } from "lucide-react"
|
||||||
|
import { Dialog as DialogPrimitive } from "radix-ui"
|
||||||
|
import * as React from "react"
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ function DialogDescription({
|
|||||||
return (
|
return (
|
||||||
<DialogPrimitive.Description
|
<DialogPrimitive.Description
|
||||||
data-slot="dialog-description"
|
data-slot="dialog-description"
|
||||||
className={cn("text-muted-foreground text-sm", className)}
|
className={cn("text-start text-muted-foreground text-sm", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
50
components/ui/dual-range-slider.tsx
Normal file
50
components/ui/dual-range-slider.tsx
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import * as SliderPrimitive from '@radix-ui/react-slider';
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
interface DualRangeSliderProps extends React.ComponentProps<typeof SliderPrimitive.Root> {
|
||||||
|
labelPosition?: 'top' | 'bottom';
|
||||||
|
label?: (value: number | undefined) => React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
const DualRangeSlider = React.forwardRef<
|
||||||
|
React.ElementRef<typeof SliderPrimitive.Root>,
|
||||||
|
DualRangeSliderProps
|
||||||
|
>(({ className, label, labelPosition = 'top', ...props }, ref) => {
|
||||||
|
const initialValue = Array.isArray(props.value) ? props.value : [props.min, props.max];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SliderPrimitive.Root
|
||||||
|
ref={ref}
|
||||||
|
className={cn('relative flex w-full touch-none select-none items-center', className)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<SliderPrimitive.Track className="relative h-2 w-full grow overflow-hidden rounded-full bg-secondary">
|
||||||
|
<SliderPrimitive.Range className="absolute h-full bg-primary" />
|
||||||
|
</SliderPrimitive.Track>
|
||||||
|
{initialValue.map((value, index) => (
|
||||||
|
<React.Fragment key={`${index + 1}`}>
|
||||||
|
<SliderPrimitive.Thumb className="relative block h-4 w-4 rounded-full border-2 border-primary bg-background ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50">
|
||||||
|
{label && (
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
'absolute flex w-full justify-center',
|
||||||
|
labelPosition === 'top' && '-top-7',
|
||||||
|
labelPosition === 'bottom' && 'top-4',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{label(value)}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</SliderPrimitive.Thumb>
|
||||||
|
</React.Fragment>
|
||||||
|
))}
|
||||||
|
</SliderPrimitive.Root>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
DualRangeSlider.displayName = 'DualRangeSlider';
|
||||||
|
|
||||||
|
export { DualRangeSlider };
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import * as React from "react"
|
|
||||||
import { Progress as ProgressPrimitive } from "radix-ui"
|
import { Progress as ProgressPrimitive } from "radix-ui"
|
||||||
|
import * as React from "react"
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
@@ -12,13 +12,13 @@ const Progress = React.forwardRef<
|
|||||||
<ProgressPrimitive.Root
|
<ProgressPrimitive.Root
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"relative h-2 w-full overflow-hidden rounded-full bg-primary/20",
|
"relative h-1 w-full overflow-hidden rounded-full bg-primary/20",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<ProgressPrimitive.Indicator
|
<ProgressPrimitive.Indicator
|
||||||
className="h-full w-full flex-1 bg-primary transition-all"
|
className={cn("h-full w-full flex-1 transition-all", className, (value ?? 0) < 20 ? "bg-red-500" : "bg-sarLinkOrange")}
|
||||||
style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
|
style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
|
||||||
/>
|
/>
|
||||||
</ProgressPrimitive.Root>
|
</ProgressPrimitive.Root>
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { Loader2, Plus } from "lucide-react";
|
||||||
|
import { useActionState, useEffect, useState } from "react"; // Import useActionState
|
||||||
|
import { toast } from "sonner";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { Loader2, Plus } from "lucide-react";
|
|
||||||
import { useActionState, useEffect, useState } from "react"; // Import useActionState
|
|
||||||
import { toast } from "sonner";
|
|
||||||
import { GetMacAccordion } from "../how-to-get-mac";
|
|
||||||
|
|
||||||
import { addDeviceAction } from "@/queries/devices";
|
import { addDeviceAction } from "@/queries/devices";
|
||||||
|
import { GetMacAccordion } from "../how-to-get-mac";
|
||||||
|
|
||||||
export type AddDeviceFormState = {
|
export type AddDeviceFormState = {
|
||||||
message: string;
|
message: string;
|
||||||
@@ -72,7 +71,7 @@ export default function AddDeviceDialogForm({ user_id }: { user_id?: string }) {
|
|||||||
<div className="grid gap-4 py-4">
|
<div className="grid gap-4 py-4">
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
<div>
|
<div>
|
||||||
<Label htmlFor="device_name" className="text-right">
|
<Label htmlFor="device_name">
|
||||||
Device Name
|
Device Name
|
||||||
</Label>
|
</Label>
|
||||||
<Input
|
<Input
|
||||||
@@ -91,7 +90,7 @@ export default function AddDeviceDialogForm({ user_id }: { user_id?: string }) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<Label htmlFor="mac_address" className="text-right">
|
<Label htmlFor="mac_address">
|
||||||
Mac Address
|
Mac Address
|
||||||
</Label>
|
</Label>
|
||||||
<Input
|
<Input
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
import { useAtom } from "jotai";
|
||||||
|
import { CircleDollarSign, Loader2, Wallet2 } from "lucide-react";
|
||||||
|
import millify from "millify";
|
||||||
|
import { usePathname, useRouter } from "next/navigation";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
import { createTopup } from "@/actions/payment";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
Drawer,
|
Drawer,
|
||||||
@@ -12,12 +19,6 @@ import {
|
|||||||
} 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 { useAtom } from "jotai";
|
|
||||||
import { CircleDollarSign, Loader2, Wallet2 } from "lucide-react";
|
|
||||||
import millify from "millify";
|
|
||||||
import { useSession } from "next-auth/react";
|
|
||||||
import { usePathname } from "next/navigation";
|
|
||||||
import { useState } from "react";
|
|
||||||
import NumberInput from "./number-input";
|
import NumberInput from "./number-input";
|
||||||
|
|
||||||
export function Wallet({
|
export function Wallet({
|
||||||
@@ -25,21 +26,18 @@ export function Wallet({
|
|||||||
}: {
|
}: {
|
||||||
walletBalance: number;
|
walletBalance: number;
|
||||||
}) {
|
}) {
|
||||||
const session = useSession();
|
|
||||||
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 = {
|
||||||
userId: session?.data?.user?.id ?? "",
|
|
||||||
amount: Number.parseFloat(amount.toFixed(2)),
|
amount: Number.parseFloat(amount.toFixed(2)),
|
||||||
paid: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -85,23 +83,20 @@ export function Wallet({
|
|||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
setDisabled(true);
|
setDisabled(true);
|
||||||
// const payment = await createPayment(data)
|
const topup = await createTopup(data)
|
||||||
setDisabled(false);
|
setDisabled(false);
|
||||||
// setMonths(1)
|
if (topup) {
|
||||||
// if (payment) {
|
router.push(`/top-ups/${topup.id}`);
|
||||||
// router.push(`/payments/${payment.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
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { User } from "./types/user";
|
||||||
|
|
||||||
export interface Links {
|
export interface Links {
|
||||||
next_page: string | null;
|
next_page: string | null;
|
||||||
previous_page: string | null;
|
previous_page: string | null;
|
||||||
@@ -45,7 +47,9 @@ export interface Device {
|
|||||||
expiry_date: string | null;
|
expiry_date: string | null;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
user: number;
|
user: Pick<User, "id" | "id_card" | "mobile"> & {
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApiError {
|
export interface ApiError {
|
||||||
@@ -53,6 +57,22 @@ export interface ApiError {
|
|||||||
detail?: string;
|
detail?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface Topup {
|
||||||
|
id: string;
|
||||||
|
amount: number;
|
||||||
|
user: Pick<User, "id" | "id_card" | "mobile"> & {
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
paid: boolean;
|
||||||
|
status: "CANCELLED" | "PENDING" | "VERIFIED";
|
||||||
|
paid_at: string | null;
|
||||||
|
mib_reference: string | null;
|
||||||
|
expires_at: string;
|
||||||
|
is_expired: boolean;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Payment {
|
export interface Payment {
|
||||||
id: string;
|
id: string;
|
||||||
devices: Device[];
|
devices: Device[];
|
||||||
@@ -61,9 +81,12 @@ export interface Payment {
|
|||||||
paid: boolean;
|
paid: boolean;
|
||||||
paid_at: string | null;
|
paid_at: string | null;
|
||||||
method: string;
|
method: string;
|
||||||
expires_at: string | null;
|
expires_at: string;
|
||||||
|
is_expired: boolean;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
|
status: "CANCELLED" | "PENDING" | "PAID";
|
||||||
|
mib_reference: string | null;
|
||||||
user: number;
|
user: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
14
lib/types.ts
14
lib/types.ts
@@ -1,9 +1,19 @@
|
|||||||
export type TopupType = {
|
export type TopupType = {
|
||||||
amount: number;
|
amount: number;
|
||||||
userId: string;
|
|
||||||
paid: boolean;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type Transaction = {
|
||||||
|
ref: string;
|
||||||
|
sourceBank: string;
|
||||||
|
trxDate: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TopupResponse = {
|
||||||
|
status: boolean;
|
||||||
|
message: string;
|
||||||
|
transaction?: Transaction
|
||||||
|
}
|
||||||
|
|
||||||
interface IpAddress {
|
interface IpAddress {
|
||||||
ip: string;
|
ip: string;
|
||||||
mask: number;
|
mask: number;
|
||||||
|
|||||||
@@ -21,6 +21,19 @@ const nextConfig: NextConfig = {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
output: "standalone",
|
output: "standalone",
|
||||||
|
async headers() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
source: '/:path*{/}?',
|
||||||
|
headers: [
|
||||||
|
{
|
||||||
|
key: 'X-Accel-Buffering',
|
||||||
|
value: 'no',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default nextConfig;
|
export default nextConfig;
|
||||||
|
|||||||
1
package-lock.json
generated
1
package-lock.json
generated
@@ -12,6 +12,7 @@
|
|||||||
"@hookform/resolvers": "^5.1.1",
|
"@hookform/resolvers": "^5.1.1",
|
||||||
"@pyncz/tailwind-mask-image": "^2.0.0",
|
"@pyncz/tailwind-mask-image": "^2.0.0",
|
||||||
"@radix-ui/react-dialog": "^1.1.14",
|
"@radix-ui/react-dialog": "^1.1.14",
|
||||||
|
"@radix-ui/react-progress": "^1.1.7",
|
||||||
"@tailwindcss/postcss": "^4.1.11",
|
"@tailwindcss/postcss": "^4.1.11",
|
||||||
"@tanstack/react-query": "^5.61.4",
|
"@tanstack/react-query": "^5.61.4",
|
||||||
"axios": "^1.8.4",
|
"axios": "^1.8.4",
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
"@hookform/resolvers": "^5.1.1",
|
"@hookform/resolvers": "^5.1.1",
|
||||||
"@pyncz/tailwind-mask-image": "^2.0.0",
|
"@pyncz/tailwind-mask-image": "^2.0.0",
|
||||||
"@radix-ui/react-dialog": "^1.1.14",
|
"@radix-ui/react-dialog": "^1.1.14",
|
||||||
|
"@radix-ui/react-progress": "^1.1.7",
|
||||||
"@tailwindcss/postcss": "^4.1.11",
|
"@tailwindcss/postcss": "^4.1.11",
|
||||||
"@tanstack/react-query": "^5.61.4",
|
"@tanstack/react-query": "^5.61.4",
|
||||||
"axios": "^1.8.4",
|
"axios": "^1.8.4",
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
"use server";
|
"use server";
|
||||||
|
|
||||||
|
import { revalidatePath } from "next/cache";
|
||||||
|
import { getServerSession } from "next-auth";
|
||||||
import { authOptions } from "@/app/auth";
|
import { authOptions } from "@/app/auth";
|
||||||
|
import { BlockDeviceFormState } from "@/components/block-device-dialog";
|
||||||
import type { AddDeviceFormState, initialState } from "@/components/user/add-device-dialog";
|
import type { AddDeviceFormState, initialState } from "@/components/user/add-device-dialog";
|
||||||
import type { ApiError, ApiResponse, Device } from "@/lib/backend-types";
|
import type { ApiError, ApiResponse, Device } from "@/lib/backend-types";
|
||||||
import { checkSession } from "@/utils/session";
|
import { checkSession } from "@/utils/session";
|
||||||
import { handleApiResponse } from "@/utils/tryCatch";
|
import { handleApiResponse } from "@/utils/tryCatch";
|
||||||
import { getServerSession } from "next-auth";
|
|
||||||
import { revalidatePath } from "next/cache";
|
|
||||||
|
|
||||||
type GetDevicesProps = {
|
type GetDevicesProps = {
|
||||||
name?: string;
|
name?: string;
|
||||||
@@ -17,7 +18,7 @@ type GetDevicesProps = {
|
|||||||
status?: string;
|
status?: string;
|
||||||
[key: string]: string | number | undefined; // Allow additional properties for flexibility
|
[key: string]: string | number | undefined; // Allow additional properties for flexibility
|
||||||
};
|
};
|
||||||
export async function getDevices(params: GetDevicesProps) {
|
export async function getDevices(params: GetDevicesProps, allDevices = false) {
|
||||||
const session = await checkSession();
|
const session = await checkSession();
|
||||||
|
|
||||||
// Build query string from all defined params
|
// Build query string from all defined params
|
||||||
@@ -27,7 +28,7 @@ export async function getDevices(params: GetDevicesProps) {
|
|||||||
.join("&");
|
.join("&");
|
||||||
|
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${process.env.SARLINK_API_BASE_URL}/api/devices/?${query}`,
|
`${process.env.SARLINK_API_BASE_URL}/api/devices/?${query}&all_devices=${allDevices}`,
|
||||||
{
|
{
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -114,32 +115,77 @@ export async function addDeviceAction(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function blockDevice({
|
export async function blockDeviceAction(
|
||||||
deviceId,
|
prevState: BlockDeviceFormState,
|
||||||
reason_for_blocking,
|
formData: FormData
|
||||||
blocked_by,
|
): Promise<BlockDeviceFormState> {
|
||||||
}: {
|
const deviceId = formData.get("deviceId") as string;
|
||||||
deviceId: string;
|
const reason_for_blocking = formData.get("reason_for_blocking") as string;
|
||||||
reason_for_blocking: string;
|
const action = formData.get("action") as "block" | "unblock" | "simple-block";
|
||||||
blocked_by: "ADMIN" | "PARENT";
|
const blocked_by = formData.get("blocked_by") as "ADMIN" | "PARENT";
|
||||||
}) {
|
|
||||||
const session = await getServerSession(authOptions);
|
try {
|
||||||
const response = await fetch(
|
const session = await getServerSession(authOptions);
|
||||||
`${process.env.SARLINK_API_BASE_URL}/api/devices/${deviceId}/block/`,
|
if (!session?.apiToken) {
|
||||||
{
|
return {
|
||||||
method: "PUT",
|
success: false,
|
||||||
headers: {
|
message: "Authentication required.",
|
||||||
"Content-Type": "application/json",
|
fieldErrors: {},
|
||||||
Authorization: `Token ${session?.apiToken}`,
|
payload: formData
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validation only for admin block with reason
|
||||||
|
if (action === "block" && session?.user?.is_superuser && (!reason_for_blocking || reason_for_blocking.trim().length < 5)) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Reason for blocking is required and must be at least 5 characters.",
|
||||||
|
fieldErrors: {
|
||||||
|
reason_for_blocking: ["Reason is required and must be at least 5 characters."]
|
||||||
|
},
|
||||||
|
payload: formData
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const isBlocking = action === "block" || action === "simple-block";
|
||||||
|
|
||||||
|
const response = await fetch(
|
||||||
|
`${process.env.SARLINK_API_BASE_URL}/api/devices/${deviceId}/block/`,
|
||||||
|
{
|
||||||
|
method: "PUT",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Token ${session.apiToken}`,
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
blocked: isBlocking,
|
||||||
|
reason_for_blocking: session?.user?.is_superuser
|
||||||
|
? reason_for_blocking || (action === "simple-block" ? "Blocked by admin" : "")
|
||||||
|
: isBlocking ? "Blocked by parent" : "",
|
||||||
|
blocked_by: session?.user?.is_superuser ? blocked_by : "PARENT",
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
);
|
||||||
blocked: true,
|
|
||||||
reason_for_blocking: session?.user?.is_superuser
|
const result = await handleApiResponse<Device>(response, "blockDeviceAction");
|
||||||
? reason_for_blocking
|
|
||||||
: "Blocked by parent",
|
revalidatePath("/devices");
|
||||||
blocked_by: session?.user?.is_superuser ? "ADMIN" : "PARENT",
|
revalidatePath("/parental-control");
|
||||||
}),
|
|
||||||
},
|
return {
|
||||||
);
|
success: true,
|
||||||
return handleApiResponse<Device>(response, "blockDevice");
|
message: isBlocking ? "Device blocked successfully!" : "Device unblocked successfully!",
|
||||||
}
|
fieldErrors: {},
|
||||||
|
payload: formData
|
||||||
|
};
|
||||||
|
|
||||||
|
} catch (error: unknown) {
|
||||||
|
console.error("Block Device Action Error:", error);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: (error as ApiError).message || "An unexpected error occurred.",
|
||||||
|
fieldErrors: {},
|
||||||
|
payload: formData
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user