From a0a5a95665f69685cde7dcf41949bfa842d98ebe Mon Sep 17 00:00:00 2001 From: sadmann7 Date: Sun, 21 Apr 2024 19:44:44 +0600 Subject: [PATCH] feat: add dashboard settings page --- drizzle/0003_clear_meteorite.sql | 8 + drizzle/0003_colossal_invisible_woman.sql | 2 - drizzle/0004_boring_colonel_america.sql | 3 - drizzle/meta/0003_snapshot.json | 791 ++++++++-------- drizzle/meta/0004_snapshot.json | 864 ------------------ drizzle/meta/_journal.json | 11 +- package.json | 4 +- pnpm-lock.yaml | 14 + .../update-notification-form-skeleton.tsx | 21 + .../_components/update-notification-form.tsx | 85 +- .../(dashboard)/dashboard/settings/page.tsx | 74 ++ .../{(helps) => }/[...slug]/not-found.tsx | 0 .../{(helps) => }/[...slug]/page.tsx | 0 .../(content)/notifications/loading.tsx | 41 - .../(content)/notifications/not-found.tsx | 15 - .../(lobby)/(content)/notifications/page.tsx | 67 -- src/components/icons.tsx | 3 +- src/components/layouts/auth-dropdown.tsx | 6 +- src/config/dashboard.ts | 6 + src/db/schema/notifications.ts | 1 + src/lib/actions/notification.ts | 18 +- src/lib/queries/notification.ts | 41 + src/lib/validations/notification.ts | 2 +- 23 files changed, 619 insertions(+), 1458 deletions(-) create mode 100644 drizzle/0003_clear_meteorite.sql delete mode 100644 drizzle/0003_colossal_invisible_woman.sql delete mode 100644 drizzle/0004_boring_colonel_america.sql delete mode 100644 drizzle/meta/0004_snapshot.json create mode 100644 src/app/(dashboard)/dashboard/settings/_components/update-notification-form-skeleton.tsx rename src/app/{(lobby)/(content)/notifications => (dashboard)/dashboard/settings}/_components/update-notification-form.tsx (64%) create mode 100644 src/app/(dashboard)/dashboard/settings/page.tsx rename src/app/(lobby)/(content)/{(helps) => }/[...slug]/not-found.tsx (100%) rename src/app/(lobby)/(content)/{(helps) => }/[...slug]/page.tsx (100%) delete mode 100644 src/app/(lobby)/(content)/notifications/loading.tsx delete mode 100644 src/app/(lobby)/(content)/notifications/not-found.tsx delete mode 100644 src/app/(lobby)/(content)/notifications/page.tsx create mode 100644 src/lib/queries/notification.ts diff --git a/drizzle/0003_clear_meteorite.sql b/drizzle/0003_clear_meteorite.sql new file mode 100644 index 000000000..81cee2a21 --- /dev/null +++ b/drizzle/0003_clear_meteorite.sql @@ -0,0 +1,8 @@ +ALTER TABLE "skateshop_notifications" RENAME COLUMN "newsletter" TO "receive_newsletter";--> statement-breakpoint +ALTER TABLE "skateshop_notifications" RENAME COLUMN "marketing" TO "receive_marketing";--> statement-breakpoint +ALTER TABLE "skateshop_notifications" DROP CONSTRAINT "skateshop_notifications_user_id_unique";--> statement-breakpoint +ALTER TABLE "skateshop_stores" DROP CONSTRAINT "skateshop_stores_user_id_unique";--> statement-breakpoint +ALTER TABLE "skateshop_subscriptions" DROP CONSTRAINT "skateshop_subscriptions_user_id_unique";--> statement-breakpoint +ALTER TABLE "skateshop_categories" ALTER COLUMN "slug" SET NOT NULL;--> statement-breakpoint +ALTER TABLE "skateshop_subcategories" ALTER COLUMN "slug" SET NOT NULL;--> statement-breakpoint +ALTER TABLE "skateshop_notifications" ADD COLUMN "receive_communication" boolean DEFAULT false NOT NULL; \ No newline at end of file diff --git a/drizzle/0003_colossal_invisible_woman.sql b/drizzle/0003_colossal_invisible_woman.sql deleted file mode 100644 index 8d9a1fc20..000000000 --- a/drizzle/0003_colossal_invisible_woman.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE "skateshop_categories" ALTER COLUMN "slug" SET NOT NULL;--> statement-breakpoint -ALTER TABLE "skateshop_subcategories" ALTER COLUMN "slug" SET NOT NULL; \ No newline at end of file diff --git a/drizzle/0004_boring_colonel_america.sql b/drizzle/0004_boring_colonel_america.sql deleted file mode 100644 index b5ec482c1..000000000 --- a/drizzle/0004_boring_colonel_america.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE "skateshop_notifications" DROP CONSTRAINT "skateshop_notifications_user_id_unique";--> statement-breakpoint -ALTER TABLE "skateshop_stores" DROP CONSTRAINT "skateshop_stores_user_id_unique";--> statement-breakpoint -ALTER TABLE "skateshop_subscriptions" DROP CONSTRAINT "skateshop_subscriptions_user_id_unique"; \ No newline at end of file diff --git a/drizzle/meta/0003_snapshot.json b/drizzle/meta/0003_snapshot.json index d8d867078..6a36a2887 100644 --- a/drizzle/meta/0003_snapshot.json +++ b/drizzle/meta/0003_snapshot.json @@ -1,11 +1,11 @@ { - "id": "794d91ff-d339-4df5-bb4c-41d2f2f7cfd9", + "id": "b6b78833-fe0e-41f0-aceb-8cc86abccf92", "prevId": "2dcb5a2d-95ad-41db-a92c-250e747b97f7", "version": "5", "dialect": "pg", "tables": { - "skateshop_addresses": { - "name": "skateshop_addresses", + "skateshop_stores": { + "name": "skateshop_stores", "schema": "", "columns": { "id": { @@ -14,39 +14,40 @@ "primaryKey": true, "notNull": true }, - "line1": { - "name": "line1", - "type": "varchar(256)", + "user_id": { + "name": "user_id", + "type": "varchar(36)", "primaryKey": false, "notNull": false }, - "line2": { - "name": "line2", - "type": "varchar(256)", + "name": { + "name": "name", + "type": "varchar", "primaryKey": false, - "notNull": false + "notNull": true }, - "city": { - "name": "city", - "type": "varchar(256)", + "description": { + "name": "description", + "type": "text", "primaryKey": false, "notNull": false }, - "state": { - "name": "state", - "type": "varchar(256)", + "slug": { + "name": "slug", + "type": "text", "primaryKey": false, "notNull": false }, - "postal_code": { - "name": "postal_code", - "type": "varchar(256)", + "active": { + "name": "active", + "type": "boolean", "primaryKey": false, - "notNull": false + "notNull": true, + "default": false }, - "country": { - "name": "country", - "type": "varchar(256)", + "stripe_account_id": { + "name": "stripe_account_id", + "type": "varchar", "primaryKey": false, "notNull": false }, @@ -68,10 +69,18 @@ "indexes": {}, "foreignKeys": {}, "compositePrimaryKeys": {}, - "uniqueConstraints": {} + "uniqueConstraints": { + "skateshop_stores_slug_unique": { + "name": "skateshop_stores_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + } }, - "skateshop_carts": { - "name": "skateshop_carts", + "skateshop_products": { + "name": "skateshop_products", "schema": "", "columns": { "id": { @@ -80,31 +89,70 @@ "primaryKey": true, "notNull": true }, - "payment_intent_id": { - "name": "payment_intent_id", + "name": { + "name": "name", "type": "varchar(256)", "primaryKey": false, - "notNull": false + "notNull": true }, - "client_secret": { - "name": "client_secret", - "type": "varchar(256)", + "description": { + "name": "description", + "type": "text", "primaryKey": false, "notNull": false }, - "items": { - "name": "items", + "images": { + "name": "images", "type": "json", "primaryKey": false, "notNull": false, "default": "'null'::json" }, - "closed": { - "name": "closed", - "type": "boolean", + "category_id": { + "name": "category_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true + }, + "subcategory_id": { + "name": "subcategory_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "price": { + "name": "price", + "type": "numeric(10, 2)", "primaryKey": false, "notNull": true, - "default": false + "default": "'0'" + }, + "inventory": { + "name": "inventory", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "rating": { + "name": "rating", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "tags": { + "name": "tags", + "type": "json", + "primaryKey": false, + "notNull": false, + "default": "'null'::json" + }, + "store_id": { + "name": "store_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true }, "created_at": { "name": "created_at", @@ -121,8 +169,57 @@ "default": "current_timestamp" } }, - "indexes": {}, - "foreignKeys": {}, + "indexes": { + "skateshop_products_store_id_idx": { + "name": "skateshop_products_store_id_idx", + "columns": [ + "store_id" + ], + "isUnique": false + }, + "skateshop_products_category_id_idx": { + "name": "skateshop_products_category_id_idx", + "columns": [ + "category_id" + ], + "isUnique": false + }, + "skateshop_products_subcategory_id_idx": { + "name": "skateshop_products_subcategory_id_idx", + "columns": [ + "subcategory_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "skateshop_products_subcategory_id_skateshop_subcategories_id_fk": { + "name": "skateshop_products_subcategory_id_skateshop_subcategories_id_fk", + "tableFrom": "skateshop_products", + "tableTo": "skateshop_subcategories", + "columnsFrom": [ + "subcategory_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "skateshop_products_store_id_skateshop_stores_id_fk": { + "name": "skateshop_products_store_id_skateshop_stores_id_fk", + "tableFrom": "skateshop_products", + "tableTo": "skateshop_stores", + "columnsFrom": [ + "store_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, "compositePrimaryKeys": {}, "uniqueConstraints": {} }, @@ -189,8 +286,8 @@ } } }, - "skateshop_notifications": { - "name": "skateshop_notifications", + "skateshop_subcategories": { + "name": "skateshop_subcategories", "schema": "", "columns": { "id": { @@ -199,43 +296,29 @@ "primaryKey": true, "notNull": true }, - "user_id": { - "name": "user_id", - "type": "varchar(36)", - "primaryKey": false, - "notNull": false - }, - "email": { - "name": "email", + "name": { + "name": "name", "type": "varchar(256)", "primaryKey": false, "notNull": true }, - "token": { - "name": "token", + "slug": { + "name": "slug", "type": "varchar(256)", "primaryKey": false, "notNull": true }, - "referred_by": { - "name": "referred_by", - "type": "varchar(256)", + "description": { + "name": "description", + "type": "text", "primaryKey": false, "notNull": false }, - "newsletter": { - "name": "newsletter", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": false - }, - "marketing": { - "name": "marketing", - "type": "boolean", + "category_id": { + "name": "category_id", + "type": "varchar(30)", "primaryKey": false, - "notNull": true, - "default": false + "notNull": true }, "created_at": { "name": "created_at", @@ -252,36 +335,51 @@ "default": "current_timestamp" } }, - "indexes": {}, - "foreignKeys": {}, + "indexes": { + "skateshop_subcategories_category_id_idx": { + "name": "skateshop_subcategories_category_id_idx", + "columns": [ + "category_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "skateshop_subcategories_category_id_skateshop_categories_id_fk": { + "name": "skateshop_subcategories_category_id_skateshop_categories_id_fk", + "tableFrom": "skateshop_subcategories", + "tableTo": "skateshop_categories", + "columnsFrom": [ + "category_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, "compositePrimaryKeys": {}, "uniqueConstraints": { - "skateshop_notifications_user_id_unique": { - "name": "skateshop_notifications_user_id_unique", - "nullsNotDistinct": false, - "columns": [ - "user_id" - ] - }, - "skateshop_notifications_email_unique": { - "name": "skateshop_notifications_email_unique", + "skateshop_subcategories_name_unique": { + "name": "skateshop_subcategories_name_unique", "nullsNotDistinct": false, "columns": [ - "email" + "name" ] }, - "skateshop_notifications_token_unique": { - "name": "skateshop_notifications_token_unique", + "skateshop_subcategories_slug_unique": { + "name": "skateshop_subcategories_slug_unique", "nullsNotDistinct": false, "columns": [ - "token" + "slug" ] } } }, - "skateshop_orders": { - "name": "skateshop_orders", - "schema": "", + "skateshop_carts": { + "name": "skateshop_carts", + "schema": "", "columns": { "id": { "name": "id", @@ -289,11 +387,17 @@ "primaryKey": true, "notNull": true }, - "store_id": { - "name": "store_id", - "type": "varchar(30)", + "payment_intent_id": { + "name": "payment_intent_id", + "type": "varchar(256)", "primaryKey": false, - "notNull": true + "notNull": false + }, + "client_secret": { + "name": "client_secret", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false }, "items": { "name": "items", @@ -302,48 +406,87 @@ "notNull": false, "default": "'null'::json" }, - "quantity": { - "name": "quantity", - "type": "integer", + "closed": { + "name": "closed", + "type": "boolean", "primaryKey": false, - "notNull": false + "notNull": true, + "default": false }, - "amount": { - "name": "amount", - "type": "numeric(10, 2)", + "created_at": { + "name": "created_at", + "type": "timestamp", "primaryKey": false, "notNull": true, - "default": "'0'" + "default": "now()" }, - "stripe_payment_intent_id": { - "name": "stripe_payment_intent_id", - "type": "varchar(256)", + "updated_at": { + "name": "updated_at", + "type": "timestamp", "primaryKey": false, + "notNull": false, + "default": "current_timestamp" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "skateshop_notifications": { + "name": "skateshop_notifications", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": true, "notNull": true }, - "stripe_payment_intent_status": { - "name": "stripe_payment_intent_status", + "user_id": { + "name": "user_id", + "type": "varchar(36)", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", "type": "varchar(256)", "primaryKey": false, "notNull": true }, - "name": { - "name": "name", + "token": { + "name": "token", "type": "varchar(256)", "primaryKey": false, "notNull": true }, - "email": { - "name": "email", + "referred_by": { + "name": "referred_by", "type": "varchar(256)", "primaryKey": false, - "notNull": true + "notNull": false }, - "address_id": { - "name": "address_id", - "type": "varchar(30)", + "receive_communication": { + "name": "receive_communication", + "type": "boolean", "primaryKey": false, - "notNull": true + "notNull": true, + "default": false + }, + "receive_newsletter": { + "name": "receive_newsletter", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "receive_marketing": { + "name": "receive_marketing", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false }, "created_at": { "name": "created_at", @@ -360,50 +503,83 @@ "default": "current_timestamp" } }, - "indexes": { - "skateshop_orders_store_id_idx": { - "name": "skateshop_orders_store_id_idx", + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "skateshop_notifications_email_unique": { + "name": "skateshop_notifications_email_unique", + "nullsNotDistinct": false, "columns": [ - "store_id" - ], - "isUnique": false + "email" + ] }, - "skateshop_orders_address_id_idx": { - "name": "skateshop_orders_address_id_idx", + "skateshop_notifications_token_unique": { + "name": "skateshop_notifications_token_unique", + "nullsNotDistinct": false, "columns": [ - "address_id" - ], - "isUnique": false + "token" + ] } - }, - "foreignKeys": { - "skateshop_orders_store_id_skateshop_stores_id_fk": { - "name": "skateshop_orders_store_id_skateshop_stores_id_fk", - "tableFrom": "skateshop_orders", - "tableTo": "skateshop_stores", - "columnsFrom": [ - "store_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" + } + }, + "skateshop_subscriptions": { + "name": "skateshop_subscriptions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": true, + "notNull": true }, - "skateshop_orders_address_id_skateshop_addresses_id_fk": { - "name": "skateshop_orders_address_id_skateshop_addresses_id_fk", - "tableFrom": "skateshop_orders", - "tableTo": "skateshop_addresses", - "columnsFrom": [ - "address_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" + "user_id": { + "name": "user_id", + "type": "varchar(36)", + "primaryKey": false, + "notNull": false + }, + "stripe_subscription_id": { + "name": "stripe_subscription_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "stripe_price_id": { + "name": "stripe_price_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "stripe_customer_id": { + "name": "stripe_customer_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "stripe_current_period_end": { + "name": "stripe_current_period_end", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "current_timestamp" } }, + "indexes": {}, + "foreignKeys": {}, "compositePrimaryKeys": {}, "uniqueConstraints": {} }, @@ -490,8 +666,8 @@ "compositePrimaryKeys": {}, "uniqueConstraints": {} }, - "skateshop_products": { - "name": "skateshop_products", + "skateshop_orders": { + "name": "skateshop_orders", "schema": "", "columns": { "id": { @@ -500,67 +676,58 @@ "primaryKey": true, "notNull": true }, - "name": { - "name": "name", - "type": "varchar(256)", + "store_id": { + "name": "store_id", + "type": "varchar(30)", "primaryKey": false, "notNull": true }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "images": { - "name": "images", + "items": { + "name": "items", "type": "json", "primaryKey": false, "notNull": false, "default": "'null'::json" }, - "category_id": { - "name": "category_id", - "type": "varchar(30)", - "primaryKey": false, - "notNull": true - }, - "subcategory_id": { - "name": "subcategory_id", - "type": "varchar(30)", + "quantity": { + "name": "quantity", + "type": "integer", "primaryKey": false, "notNull": false }, - "price": { - "name": "price", + "amount": { + "name": "amount", "type": "numeric(10, 2)", "primaryKey": false, "notNull": true, "default": "'0'" }, - "inventory": { - "name": "inventory", - "type": "integer", + "stripe_payment_intent_id": { + "name": "stripe_payment_intent_id", + "type": "varchar(256)", "primaryKey": false, - "notNull": true, - "default": 0 + "notNull": true }, - "rating": { - "name": "rating", - "type": "integer", + "stripe_payment_intent_status": { + "name": "stripe_payment_intent_status", + "type": "varchar(256)", "primaryKey": false, - "notNull": true, - "default": 0 + "notNull": true }, - "tags": { - "name": "tags", - "type": "json", + "name": { + "name": "name", + "type": "varchar(256)", "primaryKey": false, - "notNull": false, - "default": "'null'::json" + "notNull": true }, - "store_id": { - "name": "store_id", + "email": { + "name": "email", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "address_id": { + "name": "address_id", "type": "varchar(30)", "primaryKey": false, "notNull": true @@ -581,35 +748,28 @@ } }, "indexes": { - "skateshop_products_store_id_idx": { - "name": "skateshop_products_store_id_idx", + "skateshop_orders_store_id_idx": { + "name": "skateshop_orders_store_id_idx", "columns": [ "store_id" ], "isUnique": false }, - "skateshop_products_category_id_idx": { - "name": "skateshop_products_category_id_idx", - "columns": [ - "category_id" - ], - "isUnique": false - }, - "skateshop_products_subcategory_id_idx": { - "name": "skateshop_products_subcategory_id_idx", + "skateshop_orders_address_id_idx": { + "name": "skateshop_orders_address_id_idx", "columns": [ - "subcategory_id" + "address_id" ], "isUnique": false } }, "foreignKeys": { - "skateshop_products_subcategory_id_skateshop_subcategories_id_fk": { - "name": "skateshop_products_subcategory_id_skateshop_subcategories_id_fk", - "tableFrom": "skateshop_products", - "tableTo": "skateshop_subcategories", + "skateshop_orders_store_id_skateshop_stores_id_fk": { + "name": "skateshop_orders_store_id_skateshop_stores_id_fk", + "tableFrom": "skateshop_orders", + "tableTo": "skateshop_stores", "columnsFrom": [ - "subcategory_id" + "store_id" ], "columnsTo": [ "id" @@ -617,12 +777,12 @@ "onDelete": "cascade", "onUpdate": "no action" }, - "skateshop_products_store_id_skateshop_stores_id_fk": { - "name": "skateshop_products_store_id_skateshop_stores_id_fk", - "tableFrom": "skateshop_products", - "tableTo": "skateshop_stores", + "skateshop_orders_address_id_skateshop_addresses_id_fk": { + "name": "skateshop_orders_address_id_skateshop_addresses_id_fk", + "tableFrom": "skateshop_orders", + "tableTo": "skateshop_addresses", "columnsFrom": [ - "store_id" + "address_id" ], "columnsTo": [ "id" @@ -634,90 +794,8 @@ "compositePrimaryKeys": {}, "uniqueConstraints": {} }, - "skateshop_stores": { - "name": "skateshop_stores", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "varchar(30)", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "varchar(36)", - "primaryKey": false, - "notNull": false - }, - "name": { - "name": "name", - "type": "varchar", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "slug": { - "name": "slug", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "active": { - "name": "active", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": false - }, - "stripe_account_id": { - "name": "stripe_account_id", - "type": "varchar", - "primaryKey": false, - "notNull": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "current_timestamp" - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "skateshop_stores_user_id_unique": { - "name": "skateshop_stores_user_id_unique", - "nullsNotDistinct": false, - "columns": [ - "user_id" - ] - }, - "skateshop_stores_slug_unique": { - "name": "skateshop_stores_slug_unique", - "nullsNotDistinct": false, - "columns": [ - "slug" - ] - } - } - }, - "skateshop_subcategories": { - "name": "skateshop_subcategories", + "skateshop_addresses": { + "name": "skateshop_addresses", "schema": "", "columns": { "id": { @@ -726,124 +804,39 @@ "primaryKey": true, "notNull": true }, - "name": { - "name": "name", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "slug": { - "name": "slug", + "line1": { + "name": "line1", "type": "varchar(256)", "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, "notNull": false }, - "category_id": { - "name": "category_id", - "type": "varchar(30)", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "current_timestamp" - } - }, - "indexes": { - "skateshop_subcategories_category_id_idx": { - "name": "skateshop_subcategories_category_id_idx", - "columns": [ - "category_id" - ], - "isUnique": false - } - }, - "foreignKeys": { - "skateshop_subcategories_category_id_skateshop_categories_id_fk": { - "name": "skateshop_subcategories_category_id_skateshop_categories_id_fk", - "tableFrom": "skateshop_subcategories", - "tableTo": "skateshop_categories", - "columnsFrom": [ - "category_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "skateshop_subcategories_name_unique": { - "name": "skateshop_subcategories_name_unique", - "nullsNotDistinct": false, - "columns": [ - "name" - ] - }, - "skateshop_subcategories_slug_unique": { - "name": "skateshop_subcategories_slug_unique", - "nullsNotDistinct": false, - "columns": [ - "slug" - ] - } - } - }, - "skateshop_subscriptions": { - "name": "skateshop_subscriptions", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "varchar(30)", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "varchar(36)", + "line2": { + "name": "line2", + "type": "varchar(256)", "primaryKey": false, "notNull": false }, - "stripe_subscription_id": { - "name": "stripe_subscription_id", + "city": { + "name": "city", "type": "varchar(256)", "primaryKey": false, "notNull": false }, - "stripe_price_id": { - "name": "stripe_price_id", + "state": { + "name": "state", "type": "varchar(256)", "primaryKey": false, "notNull": false }, - "stripe_customer_id": { - "name": "stripe_customer_id", + "postal_code": { + "name": "postal_code", "type": "varchar(256)", "primaryKey": false, "notNull": false }, - "stripe_current_period_end": { - "name": "stripe_current_period_end", - "type": "timestamp", + "country": { + "name": "country", + "type": "varchar(256)", "primaryKey": false, "notNull": false }, @@ -865,15 +858,7 @@ "indexes": {}, "foreignKeys": {}, "compositePrimaryKeys": {}, - "uniqueConstraints": { - "skateshop_subscriptions_user_id_unique": { - "name": "skateshop_subscriptions_user_id_unique", - "nullsNotDistinct": false, - "columns": [ - "user_id" - ] - } - } + "uniqueConstraints": {} } }, "enums": {}, diff --git a/drizzle/meta/0004_snapshot.json b/drizzle/meta/0004_snapshot.json deleted file mode 100644 index 19246c26a..000000000 --- a/drizzle/meta/0004_snapshot.json +++ /dev/null @@ -1,864 +0,0 @@ -{ - "id": "dcc07c4c-deac-4d5a-b424-cea62fe5881c", - "prevId": "794d91ff-d339-4df5-bb4c-41d2f2f7cfd9", - "version": "5", - "dialect": "pg", - "tables": { - "skateshop_addresses": { - "name": "skateshop_addresses", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "varchar(30)", - "primaryKey": true, - "notNull": true - }, - "line1": { - "name": "line1", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "line2": { - "name": "line2", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "city": { - "name": "city", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "state": { - "name": "state", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "postal_code": { - "name": "postal_code", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "country": { - "name": "country", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "current_timestamp" - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "skateshop_carts": { - "name": "skateshop_carts", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "varchar(30)", - "primaryKey": true, - "notNull": true - }, - "payment_intent_id": { - "name": "payment_intent_id", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "client_secret": { - "name": "client_secret", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "items": { - "name": "items", - "type": "json", - "primaryKey": false, - "notNull": false, - "default": "'null'::json" - }, - "closed": { - "name": "closed", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "current_timestamp" - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "skateshop_categories": { - "name": "skateshop_categories", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "varchar(30)", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "slug": { - "name": "slug", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "current_timestamp" - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "skateshop_categories_name_unique": { - "name": "skateshop_categories_name_unique", - "nullsNotDistinct": false, - "columns": [ - "name" - ] - }, - "skateshop_categories_slug_unique": { - "name": "skateshop_categories_slug_unique", - "nullsNotDistinct": false, - "columns": [ - "slug" - ] - } - } - }, - "skateshop_notifications": { - "name": "skateshop_notifications", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "varchar(30)", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "varchar(36)", - "primaryKey": false, - "notNull": false - }, - "email": { - "name": "email", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "token": { - "name": "token", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "referred_by": { - "name": "referred_by", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "newsletter": { - "name": "newsletter", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": false - }, - "marketing": { - "name": "marketing", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "current_timestamp" - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "skateshop_notifications_email_unique": { - "name": "skateshop_notifications_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - }, - "skateshop_notifications_token_unique": { - "name": "skateshop_notifications_token_unique", - "nullsNotDistinct": false, - "columns": [ - "token" - ] - } - } - }, - "skateshop_orders": { - "name": "skateshop_orders", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "varchar(30)", - "primaryKey": true, - "notNull": true - }, - "store_id": { - "name": "store_id", - "type": "varchar(30)", - "primaryKey": false, - "notNull": true - }, - "items": { - "name": "items", - "type": "json", - "primaryKey": false, - "notNull": false, - "default": "'null'::json" - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": false - }, - "amount": { - "name": "amount", - "type": "numeric(10, 2)", - "primaryKey": false, - "notNull": true, - "default": "'0'" - }, - "stripe_payment_intent_id": { - "name": "stripe_payment_intent_id", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "stripe_payment_intent_status": { - "name": "stripe_payment_intent_status", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "address_id": { - "name": "address_id", - "type": "varchar(30)", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "current_timestamp" - } - }, - "indexes": { - "skateshop_orders_store_id_idx": { - "name": "skateshop_orders_store_id_idx", - "columns": [ - "store_id" - ], - "isUnique": false - }, - "skateshop_orders_address_id_idx": { - "name": "skateshop_orders_address_id_idx", - "columns": [ - "address_id" - ], - "isUnique": false - } - }, - "foreignKeys": { - "skateshop_orders_store_id_skateshop_stores_id_fk": { - "name": "skateshop_orders_store_id_skateshop_stores_id_fk", - "tableFrom": "skateshop_orders", - "tableTo": "skateshop_stores", - "columnsFrom": [ - "store_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "skateshop_orders_address_id_skateshop_addresses_id_fk": { - "name": "skateshop_orders_address_id_skateshop_addresses_id_fk", - "tableFrom": "skateshop_orders", - "tableTo": "skateshop_addresses", - "columnsFrom": [ - "address_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "skateshop_payments": { - "name": "skateshop_payments", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "varchar(30)", - "primaryKey": true, - "notNull": true - }, - "store_id": { - "name": "store_id", - "type": "varchar(30)", - "primaryKey": false, - "notNull": true - }, - "stripe_account_id": { - "name": "stripe_account_id", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "stripe_account_created_at": { - "name": "stripe_account_created_at", - "type": "integer", - "primaryKey": false, - "notNull": false - }, - "stripe_account_expires_at": { - "name": "stripe_account_expires_at", - "type": "integer", - "primaryKey": false, - "notNull": false - }, - "details_submitted": { - "name": "details_submitted", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "current_timestamp" - } - }, - "indexes": { - "skateshop_payments_store_id_idx": { - "name": "skateshop_payments_store_id_idx", - "columns": [ - "store_id" - ], - "isUnique": false - } - }, - "foreignKeys": { - "skateshop_payments_store_id_skateshop_stores_id_fk": { - "name": "skateshop_payments_store_id_skateshop_stores_id_fk", - "tableFrom": "skateshop_payments", - "tableTo": "skateshop_stores", - "columnsFrom": [ - "store_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "skateshop_products": { - "name": "skateshop_products", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "varchar(30)", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "images": { - "name": "images", - "type": "json", - "primaryKey": false, - "notNull": false, - "default": "'null'::json" - }, - "category_id": { - "name": "category_id", - "type": "varchar(30)", - "primaryKey": false, - "notNull": true - }, - "subcategory_id": { - "name": "subcategory_id", - "type": "varchar(30)", - "primaryKey": false, - "notNull": false - }, - "price": { - "name": "price", - "type": "numeric(10, 2)", - "primaryKey": false, - "notNull": true, - "default": "'0'" - }, - "inventory": { - "name": "inventory", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "rating": { - "name": "rating", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "tags": { - "name": "tags", - "type": "json", - "primaryKey": false, - "notNull": false, - "default": "'null'::json" - }, - "store_id": { - "name": "store_id", - "type": "varchar(30)", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "current_timestamp" - } - }, - "indexes": { - "skateshop_products_store_id_idx": { - "name": "skateshop_products_store_id_idx", - "columns": [ - "store_id" - ], - "isUnique": false - }, - "skateshop_products_category_id_idx": { - "name": "skateshop_products_category_id_idx", - "columns": [ - "category_id" - ], - "isUnique": false - }, - "skateshop_products_subcategory_id_idx": { - "name": "skateshop_products_subcategory_id_idx", - "columns": [ - "subcategory_id" - ], - "isUnique": false - } - }, - "foreignKeys": { - "skateshop_products_subcategory_id_skateshop_subcategories_id_fk": { - "name": "skateshop_products_subcategory_id_skateshop_subcategories_id_fk", - "tableFrom": "skateshop_products", - "tableTo": "skateshop_subcategories", - "columnsFrom": [ - "subcategory_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "skateshop_products_store_id_skateshop_stores_id_fk": { - "name": "skateshop_products_store_id_skateshop_stores_id_fk", - "tableFrom": "skateshop_products", - "tableTo": "skateshop_stores", - "columnsFrom": [ - "store_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "skateshop_stores": { - "name": "skateshop_stores", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "varchar(30)", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "varchar(36)", - "primaryKey": false, - "notNull": false - }, - "name": { - "name": "name", - "type": "varchar", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "slug": { - "name": "slug", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "active": { - "name": "active", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": false - }, - "stripe_account_id": { - "name": "stripe_account_id", - "type": "varchar", - "primaryKey": false, - "notNull": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "current_timestamp" - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "skateshop_stores_slug_unique": { - "name": "skateshop_stores_slug_unique", - "nullsNotDistinct": false, - "columns": [ - "slug" - ] - } - } - }, - "skateshop_subcategories": { - "name": "skateshop_subcategories", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "varchar(30)", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "slug": { - "name": "slug", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "category_id": { - "name": "category_id", - "type": "varchar(30)", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "current_timestamp" - } - }, - "indexes": { - "skateshop_subcategories_category_id_idx": { - "name": "skateshop_subcategories_category_id_idx", - "columns": [ - "category_id" - ], - "isUnique": false - } - }, - "foreignKeys": { - "skateshop_subcategories_category_id_skateshop_categories_id_fk": { - "name": "skateshop_subcategories_category_id_skateshop_categories_id_fk", - "tableFrom": "skateshop_subcategories", - "tableTo": "skateshop_categories", - "columnsFrom": [ - "category_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "skateshop_subcategories_name_unique": { - "name": "skateshop_subcategories_name_unique", - "nullsNotDistinct": false, - "columns": [ - "name" - ] - }, - "skateshop_subcategories_slug_unique": { - "name": "skateshop_subcategories_slug_unique", - "nullsNotDistinct": false, - "columns": [ - "slug" - ] - } - } - }, - "skateshop_subscriptions": { - "name": "skateshop_subscriptions", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "varchar(30)", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "varchar(36)", - "primaryKey": false, - "notNull": false - }, - "stripe_subscription_id": { - "name": "stripe_subscription_id", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "stripe_price_id": { - "name": "stripe_price_id", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "stripe_customer_id": { - "name": "stripe_customer_id", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "stripe_current_period_end": { - "name": "stripe_current_period_end", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "current_timestamp" - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - } - }, - "enums": {}, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index 46500a518..ce29b134f 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -26,15 +26,8 @@ { "idx": 3, "version": "5", - "when": 1709994742891, - "tag": "0003_colossal_invisible_woman", - "breakpoints": true - }, - { - "idx": 4, - "version": "5", - "when": 1710009911201, - "tag": "0004_boring_colonel_america", + "when": 1713706114262, + "tag": "0003_clear_meteorite", "breakpoints": true } ] diff --git a/package.json b/package.json index 95f4f2f62..4d3fd32b4 100644 --- a/package.json +++ b/package.json @@ -15,10 +15,11 @@ "format:check": "prettier --check \"**/*.{ts,tsx,mdx}\" --cache", "check": "pnpm lint && pnpm typecheck && pnpm format:check", "shadcn:add": "pnpm dlx shadcn-ui@latest add", + "db:generate": "dotenv drizzle-kit generate:pg", "db:introspect": "dotenv drizzle-kit introspect:pg", "db:push": "dotenv drizzle-kit push:pg", "db:migrate": "dotenv tsx src/db/migrate.ts", - "db:drop-migration": "drizzle-kit drop --config=drizzle.config.ts", + "db:drop-migration": "drizzle-kit drop", "db:seed": "dotenv tsx src/db/seed.ts", "db:studio": "dotenv drizzle-kit studio", "email:dev": "email dev --dir src/components/emails -p 3001", @@ -133,6 +134,7 @@ "rimraf": "^5.0.5", "shiki": "^1.3.0", "tailwindcss": "^3.4.3", + "tsx": "^4.7.2", "typescript": "^5.4.5", "unist-builder": "^4.0.0", "unist-util-visit": "^5.0.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9913e97ff..a336cfd69 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -319,6 +319,9 @@ devDependencies: tailwindcss: specifier: ^3.4.3 version: 3.4.3 + tsx: + specifier: ^4.7.2 + version: 4.7.2 typescript: specifier: ^5.4.5 version: 5.4.5 @@ -12113,6 +12116,17 @@ packages: typescript: 5.4.5 dev: false + /tsx@4.7.2: + resolution: {integrity: sha512-BCNd4kz6fz12fyrgCTEdZHGJ9fWTGeUzXmQysh0RVocDY3h4frk05ZNCXSy4kIenF7y/QnrdiVpTsyNRn6vlAw==} + engines: {node: '>=18.0.0'} + hasBin: true + dependencies: + esbuild: 0.19.12 + get-tsconfig: 4.7.3 + optionalDependencies: + fsevents: 2.3.3 + dev: true + /typanion@3.14.0: resolution: {integrity: sha512-ZW/lVMRabETuYCd9O9ZvMhAh8GslSqaUjxmK/JLPCh6l73CvLBiuXswj/+7LdnWOgYsQ130FqLzFz5aGT4I3Ug==} dev: false diff --git a/src/app/(dashboard)/dashboard/settings/_components/update-notification-form-skeleton.tsx b/src/app/(dashboard)/dashboard/settings/_components/update-notification-form-skeleton.tsx new file mode 100644 index 000000000..3f4b11c4b --- /dev/null +++ b/src/app/(dashboard)/dashboard/settings/_components/update-notification-form-skeleton.tsx @@ -0,0 +1,21 @@ +import { Skeleton } from "@/components/ui/skeleton" + +export function UpdateNotificationFormSkeleton() { + return ( +
+ {Array.from({ length: 3 }).map((_, i) => ( +
+
+ + +
+ +
+ ))} + +
+ ) +} diff --git a/src/app/(lobby)/(content)/notifications/_components/update-notification-form.tsx b/src/app/(dashboard)/dashboard/settings/_components/update-notification-form.tsx similarity index 64% rename from src/app/(lobby)/(content)/notifications/_components/update-notification-form.tsx rename to src/app/(dashboard)/dashboard/settings/_components/update-notification-form.tsx index a7c4a0319..3236c75a4 100644 --- a/src/app/(lobby)/(content)/notifications/_components/update-notification-form.tsx +++ b/src/app/(dashboard)/dashboard/settings/_components/update-notification-form.tsx @@ -1,15 +1,16 @@ "use client" import * as React from "react" -import { type Notification } from "@/db/schema" import { zodResolver } from "@hookform/resolvers/zod" import { useForm } from "react-hook-form" import { toast } from "sonner" -import { type z } from "zod" import { updateNotification } from "@/lib/actions/notification" -import { showErrorToast } from "@/lib/handle-error" -import { updateNotificationSchema } from "@/lib/validations/notification" +import { type getNotification } from "@/lib/queries/notification" +import { + updateNotificationSchema, + type UpdateNotificationSchema, +} from "@/lib/validations/notification" import { Button } from "@/components/ui/button" import { Form, @@ -24,59 +25,60 @@ import { Switch } from "@/components/ui/switch" import { Icons } from "@/components/icons" interface UpdateNotificationFormProps { - notification: Notification + notificationPromise: ReturnType } -type Inputs = z.infer - export function UpdateNotificationForm({ - notification, + notificationPromise, }: UpdateNotificationFormProps) { - const [isPending, startTransition] = React.useTransition() + const notification = React.use(notificationPromise) + const [loading, setLoading] = React.useState(false) - // react-hook-form - const form = useForm({ + const form = useForm({ resolver: zodResolver(updateNotificationSchema), defaultValues: { - token: notification.token, - newsletter: notification.newsletter, - marketing: notification.marketing, + token: notification?.token, + newsletter: notification?.newsletter, + marketing: notification?.marketing, }, }) - function onSubmit(data: Inputs) { - console.log(data) - startTransition(async () => { - try { - await updateNotification({ - token: data.token, - newsletter: data.newsletter, - transactional: data.transactional, - marketing: data.marketing, - }) - toast.success("Email preferences updated.") - } catch (err) { - showErrorToast(err) - } + async function onSubmit(input: UpdateNotificationSchema) { + setLoading(true) + const { error } = await updateNotification({ + token: input.token, + newsletter: input.newsletter, + communication: input.communication, + marketing: input.marketing, }) + + if (error) { + toast.error(error) + return + } + + toast.success("Preferences updated") + setLoading(false) } return (
void form.handleSubmit(onSubmit)(...args)} + className="flex w-full flex-col gap-4" + onSubmit={form.handleSubmit(onSubmit)} > ( - +
- Newsletter + + Communication emails + - Receive our monthly newsletter with the latest news and - updates. + Receive transactional emails, such as order confirmations and + shipping updates.
@@ -91,13 +93,14 @@ export function UpdateNotificationForm({ /> (
- Transactional + Newsletter emails - Receive transactional emails, order confirmations, and more. + Receive our monthly newsletter with the latest news and + updates.
@@ -116,7 +119,7 @@ export function UpdateNotificationForm({ render={({ field }) => (
- Marketing + Marketing emails Receive marketing emails, including promotions, discounts, and more. @@ -132,8 +135,8 @@ export function UpdateNotificationForm({ )} /> -