diff --git a/packages/nextjs/app/seed/placeholder-data.ts b/packages/nextjs/app/seed/placeholder-data.ts new file mode 100644 index 0000000..4f52d6a --- /dev/null +++ b/packages/nextjs/app/seed/placeholder-data.ts @@ -0,0 +1,219 @@ +// const shareholders = [ +// { +// id: '410544b2-4001-4271-9855-fec4b6a6442a', +// name: 'User', +// email: 'user@nextmail.com', +// password: '123456', +// }, +// ]; + +// const questions = [ +// { +// id: 0, +// question: 'Do you enjoy this voting application?', +// is_active: 1 +// }, +// { +// id: 1, +// question: 'Who will be Chief Executive Officer in 2025?', +// is_active: 1 +// }, +// { +// id: 2, +// question: 'Do you approve the financial report?', +// is_active: 1 +// } +// ] + +// const question_choices = [ +// { +// id: 0, +// question_id: questions[0].id, +// choice: 'Yes' +// }, +// { +// id: 1, +// question_id: questions[0].id, +// choice: 'No' +// }, +// { +// id: 2, +// question_id: questions[1].id, +// choice: 'Donald Duck' +// }, +// { +// id: 3, +// question_id: questions[1].id, +// choice: 'John Smith' +// }, +// { +// id: 4, +// question_id: questions[1].id, +// choice: 'Billy Bones' +// }, +// { +// id: 5, +// question_id: questions[2].id, +// choice: 'Yes' +// }, +// { +// id: 6, +// question_id: questions[2].id, +// choice: 'No' +// }, +// ] + +// const shareholder_question_answers = [ +// { +// sh_id: shareholders[0].id, +// q_id: question_choices[0].id, +// chice_id: question_choices[0].id, +// answer_time: '2024-12-8' +// } +// ] + +const users = [ + { + id: "410544b2-4001-4271-9855-fec4b6a6442a", + name: "User", + email: "user@nextmail.com", + password: "123456", + }, +]; + +const customers = [ + { + id: "d6e15727-9fe1-4961-8c5b-ea44a9bd81aa", + name: "Evil Rabbit", + email: "evil@rabbit.com", + image_url: "/customers/evil-rabbit.png", + }, + { + id: "3958dc9e-712f-4377-85e9-fec4b6a6442a", + name: "Delba de Oliveira", + email: "delba@oliveira.com", + image_url: "/customers/delba-de-oliveira.png", + }, + { + id: "3958dc9e-742f-4377-85e9-fec4b6a6442a", + name: "Lee Robinson", + email: "lee@robinson.com", + image_url: "/customers/lee-robinson.png", + }, + { + id: "76d65c26-f784-44a2-ac19-586678f7c2f2", + name: "Michael Novotny", + email: "michael@novotny.com", + image_url: "/customers/michael-novotny.png", + }, + { + id: "CC27C14A-0ACF-4F4A-A6C9-D45682C144B9", + name: "Amy Burns", + email: "amy@burns.com", + image_url: "/customers/amy-burns.png", + }, + { + id: "13D07535-C59E-4157-A011-F8D2EF4E0CBB", + name: "Balazs Orban", + email: "balazs@orban.com", + image_url: "/customers/balazs-orban.png", + }, +]; + +const invoices = [ + { + customer_id: customers[0].id, + amount: 15795, + status: "pending", + date: "2022-12-06", + }, + { + customer_id: customers[1].id, + amount: 20348, + status: "pending", + date: "2022-11-14", + }, + { + customer_id: customers[4].id, + amount: 3040, + status: "paid", + date: "2022-10-29", + }, + { + customer_id: customers[3].id, + amount: 44800, + status: "paid", + date: "2023-09-10", + }, + { + customer_id: customers[5].id, + amount: 34577, + status: "pending", + date: "2023-08-05", + }, + { + customer_id: customers[2].id, + amount: 54246, + status: "pending", + date: "2023-07-16", + }, + { + customer_id: customers[0].id, + amount: 666, + status: "pending", + date: "2023-06-27", + }, + { + customer_id: customers[3].id, + amount: 32545, + status: "paid", + date: "2023-06-09", + }, + { + customer_id: customers[4].id, + amount: 1250, + status: "paid", + date: "2023-06-17", + }, + { + customer_id: customers[5].id, + amount: 8546, + status: "paid", + date: "2023-06-07", + }, + { + customer_id: customers[1].id, + amount: 500, + status: "paid", + date: "2023-08-19", + }, + { + customer_id: customers[5].id, + amount: 8945, + status: "paid", + date: "2023-06-03", + }, + { + customer_id: customers[2].id, + amount: 1000, + status: "paid", + date: "2022-06-05", + }, +]; + +const revenue = [ + { month: "Jan", revenue: 2000 }, + { month: "Feb", revenue: 1800 }, + { month: "Mar", revenue: 2200 }, + { month: "Apr", revenue: 2500 }, + { month: "May", revenue: 2300 }, + { month: "Jun", revenue: 3200 }, + { month: "Jul", revenue: 3500 }, + { month: "Aug", revenue: 3700 }, + { month: "Sep", revenue: 2500 }, + { month: "Oct", revenue: 2800 }, + { month: "Nov", revenue: 3000 }, + { month: "Dec", revenue: 4800 }, +]; + +export { users, customers, invoices, revenue }; diff --git a/packages/nextjs/app/seed/route.ts b/packages/nextjs/app/seed/route.ts new file mode 100644 index 0000000..35a1629 --- /dev/null +++ b/packages/nextjs/app/seed/route.ts @@ -0,0 +1,122 @@ +import { customers, invoices, revenue, users } from "./placeholder-data"; +import { db } from "@vercel/postgres"; +import bcrypt from "bcrypt"; + +const client = await db.connect(); + +async function seedUsers() { + await client.sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`; + await client.sql` + CREATE TABLE IF NOT EXISTS users ( + id UUID DEFAULT uuid_generate_v4() PRIMARY KEY, + name VARCHAR(255) NOT NULL, + email TEXT NOT NULL UNIQUE, + password TEXT NOT NULL + ); + `; + + const insertedUsers = await Promise.all( + users.map(async user => { + const hashedPassword = await bcrypt.hash(user.password, 10); + return client.sql` + INSERT INTO users (id, name, email, password) + VALUES (${user.id}, ${user.name}, ${user.email}, ${hashedPassword}) + ON CONFLICT (id) DO NOTHING; + `; + }), + ); + + return insertedUsers; +} + +async function seedInvoices() { + await client.sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`; + + await client.sql` + CREATE TABLE IF NOT EXISTS invoices ( + id UUID DEFAULT uuid_generate_v4() PRIMARY KEY, + customer_id UUID NOT NULL, + amount INT NOT NULL, + status VARCHAR(255) NOT NULL, + date DATE NOT NULL + ); + `; + + const insertedInvoices = await Promise.all( + invoices.map( + invoice => client.sql` + INSERT INTO invoices (customer_id, amount, status, date) + VALUES (${invoice.customer_id}, ${invoice.amount}, ${invoice.status}, ${invoice.date}) + ON CONFLICT (id) DO NOTHING; + `, + ), + ); + + return insertedInvoices; +} + +async function seedCustomers() { + await client.sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`; + + await client.sql` + CREATE TABLE IF NOT EXISTS customers ( + id UUID DEFAULT uuid_generate_v4() PRIMARY KEY, + name VARCHAR(255) NOT NULL, + email VARCHAR(255) NOT NULL, + image_url VARCHAR(255) NOT NULL + ); + `; + + const insertedCustomers = await Promise.all( + customers.map( + customer => client.sql` + INSERT INTO customers (id, name, email, image_url) + VALUES (${customer.id}, ${customer.name}, ${customer.email}, ${customer.image_url}) + ON CONFLICT (id) DO NOTHING; + `, + ), + ); + + return insertedCustomers; +} + +async function seedRevenue() { + await client.sql` + CREATE TABLE IF NOT EXISTS revenue ( + month VARCHAR(4) NOT NULL UNIQUE, + revenue INT NOT NULL + ); + `; + + const insertedRevenue = await Promise.all( + revenue.map( + rev => client.sql` + INSERT INTO revenue (month, revenue) + VALUES (${rev.month}, ${rev.revenue}) + ON CONFLICT (month) DO NOTHING; + `, + ), + ); + + return insertedRevenue; +} + +export async function GET() { + // return Response.json({ + // message: + // 'Uncomment this file and remove this line. You can delete this file when you are finished.', + // }); + try { + await client.sql`BEGIN`; + await seedUsers(); + await seedCustomers(); + await seedInvoices(); + await seedRevenue(); + await client.sql`COMMIT`; + + return Response.json({ message: "Database seeded successfully" }); + } catch (error) { + await client.sql`ROLLBACK`; + return Response.json({ error }, { status: 500 }); + } +} diff --git a/packages/nextjs/app/voting/_components/Voting.tsx b/packages/nextjs/app/voting/_components/Voting.tsx new file mode 100644 index 0000000..a5d3759 --- /dev/null +++ b/packages/nextjs/app/voting/_components/Voting.tsx @@ -0,0 +1,37 @@ +"use client"; + +import React, { useState } from "react"; + +const Voting = () => { + // Initialize state to keep track of vote counts + const [voteCount, setVoteCount] = useState(0); + + // Handler function to increment the vote count for upvote + const handleUpvote = () => { + setVoteCount(voteCount + 1); + }; + + // Handler function to decrement the vote count for downvote + const handleDownvote = () => { + setVoteCount(voteCount - 1); + }; + + return ( +
+

Vote on this post

+
+ + +
+
+

Current Vote Count: {voteCount}

+
+
+ ); +}; + +export default Voting; diff --git a/packages/nextjs/app/voting/page.tsx b/packages/nextjs/app/voting/page.tsx index 13db668..973d7c8 100644 --- a/packages/nextjs/app/voting/page.tsx +++ b/packages/nextjs/app/voting/page.tsx @@ -1,7 +1,9 @@ +import Voting from "./_components/Voting"; + export default function Page() { return ( <> -

Voting Page

+ ); } diff --git a/packages/nextjs/package.json b/packages/nextjs/package.json index 8e685be..26b9e3e 100644 --- a/packages/nextjs/package.json +++ b/packages/nextjs/package.json @@ -17,8 +17,10 @@ "@heroicons/react": "^2.0.11", "@rainbow-me/rainbowkit": "2.1.2", "@tanstack/react-query": "^5.28.6", + "@types/bcrypt": "^5.0.0", "@uniswap/sdk-core": "^4.0.1", "@uniswap/v2-sdk": "^3.0.1", + "@vercel/postgres": "^0.10.0", "blo": "^1.0.1", "burner-connector": "^0.0.8", "daisyui": "4.5.0", diff --git a/yarn.lock b/yarn.lock index 983b1f6..74c7842 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1212,6 +1212,15 @@ __metadata: languageName: node linkType: hard +"@neondatabase/serverless@npm:^0.9.3": + version: 0.9.5 + resolution: "@neondatabase/serverless@npm:0.9.5" + dependencies: + "@types/pg": 8.11.6 + checksum: b53c4b21c6eaf995a12bd84adf2c839022b7eb8b216cb07319a784a6f60965cf9ae497560a2aa767f5f8a407f1a45783f13b9f9e8f5c2078118a6a5ae174fdb2 + languageName: node + linkType: hard + "@next/env@npm:14.2.19": version: 14.2.19 resolution: "@next/env@npm:14.2.19" @@ -2056,6 +2065,7 @@ __metadata: "@rainbow-me/rainbowkit": 2.1.2 "@tanstack/react-query": ^5.28.6 "@trivago/prettier-plugin-sort-imports": ^4.1.1 + "@types/bcrypt": ^5.0.0 "@types/node": ^17.0.35 "@types/nprogress": ^0 "@types/react": ^18.0.9 @@ -2063,6 +2073,7 @@ __metadata: "@typescript-eslint/eslint-plugin": ^5.39.0 "@uniswap/sdk-core": ^4.0.1 "@uniswap/v2-sdk": ^3.0.1 + "@vercel/postgres": ^0.10.0 abitype: 1.0.5 autoprefixer: ^10.4.12 blo: ^1.0.1 @@ -2522,6 +2533,15 @@ __metadata: languageName: node linkType: hard +"@types/bcrypt@npm:^5.0.0": + version: 5.0.2 + resolution: "@types/bcrypt@npm:5.0.2" + dependencies: + "@types/node": "*" + checksum: b1f97532ffe6079cb57a464f28b5b37a30bc9620f43469e1f27ab9c979c8a114be5b667e7b115a5556fd5be463b65968da9bb32573c6faf74fecf6e565d8974b + languageName: node + linkType: hard + "@types/bn.js@npm:^4.11.3": version: 4.11.6 resolution: "@types/bn.js@npm:4.11.6" @@ -2730,6 +2750,17 @@ __metadata: languageName: node linkType: hard +"@types/pg@npm:8.11.6": + version: 8.11.6 + resolution: "@types/pg@npm:8.11.6" + dependencies: + "@types/node": "*" + pg-protocol: "*" + pg-types: ^4.0.1 + checksum: 231f7e5bfe8b4d14cca398d24cd55f4f14f582f815b62059e6f3ee74108cf92089fbd946568ebc35fa402f238ed9c8a8c1e10e7084e83e4ca3aff75957243014 + languageName: node + linkType: hard + "@types/prettier@npm:^2, @types/prettier@npm:^2.1.1": version: 2.7.3 resolution: "@types/prettier@npm:2.7.3" @@ -3244,6 +3275,17 @@ __metadata: languageName: node linkType: hard +"@vercel/postgres@npm:^0.10.0": + version: 0.10.0 + resolution: "@vercel/postgres@npm:0.10.0" + dependencies: + "@neondatabase/serverless": ^0.9.3 + bufferutil: ^4.0.8 + ws: ^8.17.1 + checksum: 45c29baa73bed4b07a5c06ae283647d43c89d843ebd3cb4864b59ec4217ef5d24832e569cd08d61f8b7875522fc207bb364547ea7e9423dd37521fba24ccec20 + languageName: node + linkType: hard + "@vercel/python@npm:4.1.0": version: 4.1.0 resolution: "@vercel/python@npm:4.1.0" @@ -10300,6 +10342,13 @@ __metadata: languageName: node linkType: hard +"obuf@npm:~1.1.2": + version: 1.1.2 + resolution: "obuf@npm:1.1.2" + checksum: 41a2ba310e7b6f6c3b905af82c275bf8854896e2e4c5752966d64cbcd2f599cfffd5932006bcf3b8b419dfdacebb3a3912d5d94e10f1d0acab59876c8757f27f + languageName: node + linkType: hard + "ofetch@npm:^1.4.1": version: 1.4.1 resolution: "ofetch@npm:1.4.1" @@ -10643,6 +10692,42 @@ __metadata: languageName: node linkType: hard +"pg-int8@npm:1.0.1": + version: 1.0.1 + resolution: "pg-int8@npm:1.0.1" + checksum: a1e3a05a69005ddb73e5f324b6b4e689868a447c5fa280b44cd4d04e6916a344ac289e0b8d2695d66e8e89a7fba023affb9e0e94778770ada5df43f003d664c9 + languageName: node + linkType: hard + +"pg-numeric@npm:1.0.2": + version: 1.0.2 + resolution: "pg-numeric@npm:1.0.2" + checksum: 8899f8200caa1744439a8778a9eb3ceefb599d893e40a09eef84ee0d4c151319fd416634a6c0fc7b7db4ac268710042da5be700b80ef0de716fe089b8652c84f + languageName: node + linkType: hard + +"pg-protocol@npm:*": + version: 1.7.0 + resolution: "pg-protocol@npm:1.7.0" + checksum: 2dba740f6fc4b7f9761682c4c42d183b444292cdc7638b373f5247ec995c8199c369953343479281da3c41611fe34130a80c8668348d49a399c164f802f76be2 + languageName: node + linkType: hard + +"pg-types@npm:^4.0.1": + version: 4.0.2 + resolution: "pg-types@npm:4.0.2" + dependencies: + pg-int8: 1.0.1 + pg-numeric: 1.0.2 + postgres-array: ~3.0.1 + postgres-bytea: ~3.0.0 + postgres-date: ~2.1.0 + postgres-interval: ^3.0.0 + postgres-range: ^1.1.1 + checksum: c4b813382d4a75f87462fab3245d5422b86ba1a54a1b330e6b43a459c127b4d02553dc7e5b4ae4fa0f5f17971d416eb393810f69ff6d30d986e45c2f20778c55 + languageName: node + linkType: hard + "picocolors@npm:1.0.0": version: 1.0.0 resolution: "picocolors@npm:1.0.0" @@ -10877,6 +10962,43 @@ __metadata: languageName: node linkType: hard +"postgres-array@npm:~3.0.1": + version: 3.0.2 + resolution: "postgres-array@npm:3.0.2" + checksum: 5955f9dffeb6fa960c1a0b04fd4b2ba16813ddb636934ad26f902e4d76a91c0b743dcc6edc4cffc52deba7d547505e0020adea027c1d50a774f989cf955420d1 + languageName: node + linkType: hard + +"postgres-bytea@npm:~3.0.0": + version: 3.0.0 + resolution: "postgres-bytea@npm:3.0.0" + dependencies: + obuf: ~1.1.2 + checksum: 5f917a003fcaa0df7f285e1c37108ad474ce91193466b9bd4bcaecef2cdea98ca069c00aa6a8dbe6d2e7192336cadc3c9b36ae48d1555a299521918e00e2936b + languageName: node + linkType: hard + +"postgres-date@npm:~2.1.0": + version: 2.1.0 + resolution: "postgres-date@npm:2.1.0" + checksum: 5c573b0602e17c6134fd8bc8ac7689ac0302e1b199f15dd3578fc45186f206dbd0609f97bf0e4bd1db62234d7a37f29c04f4df525f7efebb9304363b2efca272 + languageName: node + linkType: hard + +"postgres-interval@npm:^3.0.0": + version: 3.0.0 + resolution: "postgres-interval@npm:3.0.0" + checksum: c7a1cf006de97de663b6b8c4d2b167aa9909a238c4866a94b15d303762f5ac884ff4796cd6e2111b7f0a91302b83c570453aa8506fd005b5a5d5dfa87441bebc + languageName: node + linkType: hard + +"postgres-range@npm:^1.1.1": + version: 1.1.4 + resolution: "postgres-range@npm:1.1.4" + checksum: 460af8c882a50e2c3d08ede5d5ee9e5e5a99dcf471e3ed55b4c17cad62dc85177b51bb8105b626a9c73de9edcba934e86665923b0d86e1c8e1f55d3e0f3530c6 + languageName: node + linkType: hard + "preact@npm:^10.16.0": version: 10.25.1 resolution: "preact@npm:10.25.1" @@ -14071,6 +14193,21 @@ __metadata: languageName: node linkType: hard +"ws@npm:^8.17.1": + version: 8.18.0 + resolution: "ws@npm:8.18.0" + peerDependencies: + bufferutil: ^4.0.1 + utf-8-validate: ">=5.0.2" + peerDependenciesMeta: + bufferutil: + optional: true + utf-8-validate: + optional: true + checksum: 91d4d35bc99ff6df483bdf029b9ea4bfd7af1f16fc91231a96777a63d263e1eabf486e13a2353970efc534f9faa43bdbf9ee76525af22f4752cbc5ebda333975 + languageName: node + linkType: hard + "xdg-app-paths@npm:5.1.0": version: 5.1.0 resolution: "xdg-app-paths@npm:5.1.0"