@86d-app/products 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/AGENTS.md +65 -0
  2. package/COMPONENTS.md +231 -0
  3. package/README.md +201 -0
  4. package/package.json +46 -0
  5. package/src/__tests__/controllers.test.ts +2227 -0
  6. package/src/__tests__/state.test.ts +138 -0
  7. package/src/admin/components/categories-admin.mdx +3 -0
  8. package/src/admin/components/categories-admin.tsx +449 -0
  9. package/src/admin/components/category-form.mdx +9 -0
  10. package/src/admin/components/category-form.tsx +490 -0
  11. package/src/admin/components/category-list.mdx +75 -0
  12. package/src/admin/components/category-list.tsx +168 -0
  13. package/src/admin/components/collections-admin.mdx +3 -0
  14. package/src/admin/components/collections-admin.tsx +771 -0
  15. package/src/admin/components/index.tsx +8 -0
  16. package/src/admin/components/product-detail.mdx +12 -0
  17. package/src/admin/components/product-detail.tsx +790 -0
  18. package/src/admin/components/product-edit.tsx +60 -0
  19. package/src/admin/components/product-form.tsx +793 -0
  20. package/src/admin/components/product-list.mdx +3 -0
  21. package/src/admin/components/product-list.tsx +1125 -0
  22. package/src/admin/components/product-new.tsx +38 -0
  23. package/src/admin/endpoints/add-collection-product.ts +17 -0
  24. package/src/admin/endpoints/bulk-action.ts +43 -0
  25. package/src/admin/endpoints/create-category.ts +52 -0
  26. package/src/admin/endpoints/create-collection.ts +35 -0
  27. package/src/admin/endpoints/create-product.ts +50 -0
  28. package/src/admin/endpoints/create-variant.ts +45 -0
  29. package/src/admin/endpoints/delete-category.ts +27 -0
  30. package/src/admin/endpoints/delete-collection.ts +12 -0
  31. package/src/admin/endpoints/delete-product.ts +27 -0
  32. package/src/admin/endpoints/delete-variant.ts +27 -0
  33. package/src/admin/endpoints/get-product.ts +23 -0
  34. package/src/admin/endpoints/import-products.ts +47 -0
  35. package/src/admin/endpoints/index.ts +43 -0
  36. package/src/admin/endpoints/list-categories.ts +21 -0
  37. package/src/admin/endpoints/list-collections.ts +20 -0
  38. package/src/admin/endpoints/list-products.ts +25 -0
  39. package/src/admin/endpoints/remove-collection-product.ts +15 -0
  40. package/src/admin/endpoints/update-category.ts +82 -0
  41. package/src/admin/endpoints/update-collection.ts +22 -0
  42. package/src/admin/endpoints/update-product.ts +67 -0
  43. package/src/admin/endpoints/update-variant.ts +41 -0
  44. package/src/controllers.ts +1410 -0
  45. package/src/index.ts +120 -0
  46. package/src/markdown.ts +150 -0
  47. package/src/mdx.d.ts +5 -0
  48. package/src/schema.ts +352 -0
  49. package/src/state.ts +84 -0
  50. package/src/store/components/_hooks.ts +78 -0
  51. package/src/store/components/_types.ts +73 -0
  52. package/src/store/components/_utils.ts +14 -0
  53. package/src/store/components/back-in-stock-notify.tsx +97 -0
  54. package/src/store/components/collection-card.mdx +42 -0
  55. package/src/store/components/collection-card.tsx +12 -0
  56. package/src/store/components/collection-detail.mdx +12 -0
  57. package/src/store/components/collection-detail.tsx +149 -0
  58. package/src/store/components/collection-grid.mdx +9 -0
  59. package/src/store/components/collection-grid.tsx +80 -0
  60. package/src/store/components/featured-products.mdx +9 -0
  61. package/src/store/components/featured-products.tsx +75 -0
  62. package/src/store/components/filter-chip.mdx +25 -0
  63. package/src/store/components/filter-chip.tsx +12 -0
  64. package/src/store/components/index.tsx +39 -0
  65. package/src/store/components/product-card.mdx +69 -0
  66. package/src/store/components/product-card.tsx +71 -0
  67. package/src/store/components/product-detail.mdx +30 -0
  68. package/src/store/components/product-detail.tsx +488 -0
  69. package/src/store/components/product-listing.mdx +7 -0
  70. package/src/store/components/product-listing.tsx +423 -0
  71. package/src/store/components/product-reviews-section.mdx +21 -0
  72. package/src/store/components/product-reviews-section.tsx +372 -0
  73. package/src/store/components/recently-viewed.tsx +100 -0
  74. package/src/store/components/related-products.mdx +6 -0
  75. package/src/store/components/related-products.tsx +62 -0
  76. package/src/store/components/star-display.mdx +18 -0
  77. package/src/store/components/star-display.tsx +27 -0
  78. package/src/store/components/star-picker.mdx +21 -0
  79. package/src/store/components/star-picker.tsx +21 -0
  80. package/src/store/components/stock-badge.mdx +12 -0
  81. package/src/store/components/stock-badge.tsx +19 -0
  82. package/src/store/endpoints/get-category.ts +61 -0
  83. package/src/store/endpoints/get-collection.ts +46 -0
  84. package/src/store/endpoints/get-featured.ts +18 -0
  85. package/src/store/endpoints/get-product.ts +52 -0
  86. package/src/store/endpoints/get-related.ts +20 -0
  87. package/src/store/endpoints/index.ts +23 -0
  88. package/src/store/endpoints/list-categories.ts +13 -0
  89. package/src/store/endpoints/list-collections.ts +22 -0
  90. package/src/store/endpoints/list-products.ts +28 -0
  91. package/src/store/endpoints/search-products.ts +18 -0
  92. package/src/store/endpoints/store-search.ts +111 -0
  93. package/tsconfig.json +9 -0
  94. package/vitest.config.ts +7 -0
@@ -0,0 +1,168 @@
1
+ "use client";
2
+
3
+ import { useModuleClient } from "@86d-app/core/client";
4
+ import { useState } from "react";
5
+ import CategoryListTemplate from "./category-list.mdx";
6
+
7
+ // ─── Types ────────────────────────────────────────────────────────────────────
8
+
9
+ interface Category {
10
+ id: string;
11
+ name: string;
12
+ slug: string;
13
+ description?: string | null;
14
+ parentId?: string | null;
15
+ image?: string | null;
16
+ position: number;
17
+ isVisible: boolean;
18
+ createdAt: string;
19
+ _count?: { products?: number };
20
+ }
21
+
22
+ interface ListResult {
23
+ categories: Category[];
24
+ total: number;
25
+ page: number;
26
+ limit: number;
27
+ }
28
+
29
+ // ─── Module Client ───────────────────────────────────────────────────────────
30
+
31
+ function useCategoriesAdminApi() {
32
+ const client = useModuleClient();
33
+ return {
34
+ listCategories: client.module("products").admin["/admin/categories/list"],
35
+ deleteCategory:
36
+ client.module("products").admin["/admin/categories/:id/delete"],
37
+ };
38
+ }
39
+
40
+ // ─── CategoryList ─────────────────────────────────────────────────────────────
41
+
42
+ interface CategoryListProps {
43
+ onCreateNew?: () => void;
44
+ onEdit?: (categoryId: string) => void;
45
+ }
46
+
47
+ export function CategoryList({ onCreateNew, onEdit }: CategoryListProps) {
48
+ const api = useCategoriesAdminApi();
49
+
50
+ const [page, setPage] = useState(1);
51
+ const [deleting, setDeleting] = useState<string | null>(null);
52
+
53
+ const limit = 20;
54
+
55
+ const { data: categoriesData, isLoading: loading } =
56
+ api.listCategories.useQuery({
57
+ page: String(page),
58
+ limit: String(limit),
59
+ }) as { data: ListResult | undefined; isLoading: boolean };
60
+
61
+ const deleteMutation = api.deleteCategory.useMutation({
62
+ onSettled: () => {
63
+ setDeleting(null);
64
+ void api.listCategories.invalidate();
65
+ },
66
+ });
67
+
68
+ const categories = categoriesData?.categories ?? [];
69
+ const total = categoriesData?.total ?? 0;
70
+ const totalPages = Math.ceil(total / limit);
71
+
72
+ const handleDelete = (id: string) => {
73
+ if (!window.confirm("Are you sure you want to delete this category?")) {
74
+ return;
75
+ }
76
+ setDeleting(id);
77
+ deleteMutation.mutate({ params: { id } });
78
+ };
79
+
80
+ const tableBody = loading ? (
81
+ Array.from({ length: 5 }).map((_, i) => (
82
+ <tr key={i}>
83
+ <td className="px-4 py-3">
84
+ <div className="h-4 w-28 animate-pulse rounded bg-muted" />
85
+ </td>
86
+ <td className="px-4 py-3">
87
+ <div className="h-4 w-24 animate-pulse rounded bg-muted" />
88
+ </td>
89
+ <td className="px-4 py-3">
90
+ <div className="h-5 w-14 animate-pulse rounded-full bg-muted" />
91
+ </td>
92
+ <td className="px-4 py-3">
93
+ <div className="h-4 w-8 animate-pulse rounded bg-muted" />
94
+ </td>
95
+ <td className="px-4 py-3">
96
+ <div className="h-4 w-8 animate-pulse rounded bg-muted" />
97
+ </td>
98
+ <td className="px-4 py-3">
99
+ <div className="h-4 w-24 animate-pulse rounded bg-muted" />
100
+ </td>
101
+ </tr>
102
+ ))
103
+ ) : categories.length === 0 ? (
104
+ <tr>
105
+ <td colSpan={6} className="px-4 py-12 text-center text-muted-foreground">
106
+ <p className="font-medium text-foreground">No categories found</p>
107
+ <p className="mt-1 text-sm">
108
+ Create your first category to organize products.
109
+ </p>
110
+ </td>
111
+ </tr>
112
+ ) : (
113
+ categories.map((cat) => (
114
+ <tr key={cat.id} className="transition-colors hover:bg-muted/30">
115
+ <td className="px-4 py-3 font-medium text-foreground">{cat.name}</td>
116
+ <td className="px-4 py-3 font-mono text-muted-foreground">
117
+ {cat.slug}
118
+ </td>
119
+ <td className="px-4 py-3">
120
+ {cat.isVisible ? (
121
+ <span className="inline-flex rounded-full bg-emerald-50 px-2 py-0.5 font-medium text-emerald-700 text-xs dark:bg-emerald-950 dark:text-emerald-300">
122
+ Visible
123
+ </span>
124
+ ) : (
125
+ <span className="inline-flex rounded-full bg-muted px-2 py-0.5 font-medium text-muted-foreground text-xs">
126
+ Hidden
127
+ </span>
128
+ )}
129
+ </td>
130
+ <td className="px-4 py-3 text-foreground">{cat.position}</td>
131
+ <td className="px-4 py-3 text-foreground">
132
+ {cat._count?.products ?? 0}
133
+ </td>
134
+ <td className="px-4 py-3 text-right">
135
+ <div className="flex items-center justify-end gap-2">
136
+ <button
137
+ type="button"
138
+ onClick={() => onEdit?.(cat.id)}
139
+ className="rounded-md px-2 py-1 text-muted-foreground text-xs transition-colors hover:bg-muted hover:text-foreground"
140
+ >
141
+ Edit
142
+ </button>
143
+ <button
144
+ type="button"
145
+ onClick={() => handleDelete(cat.id)}
146
+ disabled={deleting === cat.id}
147
+ className="rounded-md px-2 py-1 text-destructive text-xs transition-colors hover:bg-destructive/10 disabled:opacity-50"
148
+ >
149
+ {deleting === cat.id ? "Deleting..." : "Delete"}
150
+ </button>
151
+ </div>
152
+ </td>
153
+ </tr>
154
+ ))
155
+ );
156
+
157
+ return (
158
+ <CategoryListTemplate
159
+ total={total}
160
+ onCreateNew={onCreateNew}
161
+ tableBody={tableBody}
162
+ totalPages={totalPages}
163
+ page={page}
164
+ onPrevPage={() => setPage((p) => Math.max(1, p - 1))}
165
+ onNextPage={() => setPage((p) => Math.min(totalPages, p + 1))}
166
+ />
167
+ );
168
+ }
@@ -0,0 +1,3 @@
1
+ <div>
2
+ {props.content}
3
+ </div>