Enhance dashboard functionality with new payment and device management features

- Added new PaymentPage component for processing payments and displaying devices to pay.
- Introduced DeviceDetails component for viewing individual device information.
- Implemented PriceCalculator component for calculating costs based on user input.
- Integrated Jotai for state management across components, including device cart functionality.
- Updated layout to include Jotai Provider for state management.
- Enhanced DevicesTable with AddDevicesToCartButton for adding devices to the cart.
- Refactored sidebar to include a link to the new Price Calculator page.
- Updated Prisma schema to include Payment and BillFormula models for better data handling.
- Added new UI components for device cart management and drawer functionality.
- Improved overall user experience with responsive design adjustments and new UI elements.
This commit is contained in:
2024-12-06 14:16:05 +05:00
parent 9021f01ff4
commit c6f45710ca
23 changed files with 2545 additions and 50 deletions

View File

@ -0,0 +1,29 @@
-- AlterTable
ALTER TABLE "user" ADD COLUMN "policyAccepted" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN "termsAccepted" BOOLEAN NOT NULL DEFAULT false;
-- CreateTable
CREATE TABLE "Bill" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"amount" INTEGER NOT NULL,
"paid" BOOLEAN NOT NULL DEFAULT false,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"deviceId" TEXT,
CONSTRAINT "Bill_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "BillFormula" (
"id" TEXT NOT NULL,
"formula" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "BillFormula_pkey" PRIMARY KEY ("id")
);
-- AddForeignKey
ALTER TABLE "Bill" ADD CONSTRAINT "Bill_deviceId_fkey" FOREIGN KEY ("deviceId") REFERENCES "Device"("id") ON DELETE SET NULL ON UPDATE CASCADE;

View File

@ -0,0 +1,10 @@
/*
Warnings:
- Added the required column `baseAmount` to the `BillFormula` table without a default value. This is not possible if the table is not empty.
- Added the required column `discountPercentage` to the `BillFormula` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "BillFormula" ADD COLUMN "baseAmount" DOUBLE PRECISION NOT NULL,
ADD COLUMN "discountPercentage" DOUBLE PRECISION NOT NULL;

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Device" ADD COLUMN "isActive" BOOLEAN NOT NULL DEFAULT false;

View File

@ -0,0 +1,33 @@
/*
Warnings:
- You are about to drop the `Bill` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropForeignKey
ALTER TABLE "Bill" DROP CONSTRAINT "Bill_deviceId_fkey";
-- AlterTable
ALTER TABLE "Device" ADD COLUMN "billId" TEXT;
-- DropTable
DROP TABLE "Bill";
-- CreateTable
CREATE TABLE "Payment" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"amount" INTEGER NOT NULL,
"paid" BOOLEAN NOT NULL DEFAULT false,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"userId" TEXT NOT NULL,
CONSTRAINT "Payment_pkey" PRIMARY KEY ("id")
);
-- AddForeignKey
ALTER TABLE "Device" ADD CONSTRAINT "Device_billId_fkey" FOREIGN KEY ("billId") REFERENCES "Payment"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Payment" ADD CONSTRAINT "Payment_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@ -41,6 +41,7 @@ model User {
lang String?
atollId String?
islandId String?
Bill Payment[]
@@map("user")
}
@ -108,12 +109,36 @@ model Island {
}
model Device {
id String @id @default(cuid())
name String
mac String
id String @id @default(cuid())
name String
mac String
isActive Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
User User? @relation(fields: [userId], references: [id])
userId String?
Bill Payment? @relation(fields: [billId], references: [id])
billId String?
}
model Payment {
id String @id @default(cuid())
name String
amount Int
paid Boolean @default(false)
user User @relation(fields: [userId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
devices Device[]
userId String
}
model BillFormula {
id String @id @default(cuid())
formula String
baseAmount Float
discountPercentage Float
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

View File

@ -6,6 +6,25 @@ const prisma = new PrismaClient();
const DEFAULT_ISLANDS = ["Dharanboodhoo", "Feeali", "Nilandhoo", "Magoodhoo"];
async function main() {
await prisma.user.upsert({
where: {
phoneNumber: "+9607780588",
},
update: {},
create: {
name: "Admin",
email: "admin@sarlink.net",
emailVerified: true,
firstPaymentDone: true,
verified: true,
address: "Dharanboodhoo",
id_card: "A265117",
dob: new Date("1990-01-01"),
phoneNumber: "+9607780588",
phoneNumberVerified: true,
role: "ADMIN",
},
});
const users = Array.from({ length: 25 }, () => ({
name: `${faker.person.fullName().split(" ")[1]} House-${crypto
.randomUUID()
@ -25,8 +44,18 @@ async function main() {
role: "USER",
}));
await prisma.user.createMany({
data: users,
const seedUsers = await Promise.all(
users.map((user) => prisma.user.create({ data: user })),
);
const FAKE_DEVICES = Array.from({ length: 25 }, () => ({
name: faker.commerce.productName(),
mac: faker.internet.mac(),
userId: seedUsers[Math.floor(Math.random() * seedUsers.length)].id,
}));
await prisma.device.createMany({
data: FAKE_DEVICES,
});
const FAAFU_ATOLL = await prisma.atoll.create({
data: {