robodev 0.23.0 → 0.24.0

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 (176) hide show
  1. package/package.json +1 -1
  2. package/src/emit-starter.test.ts +36 -0
  3. package/templates/auth-chat/package.json +1 -1
  4. package/templates/backend/package.json +1 -1
  5. package/templates/catalog.json +5 -0
  6. package/templates/empty/package.json +1 -1
  7. package/templates/marketplace/.config/local.spa.template.yml +27 -0
  8. package/templates/marketplace/.oxlint-base.json +29 -0
  9. package/templates/marketplace/.oxlintrc.json +78 -0
  10. package/templates/marketplace/.rulesync/rules/frontend-api-boundary.md +36 -0
  11. package/templates/marketplace/.rulesync/rules/frontend-component-structure.md +38 -0
  12. package/templates/marketplace/.rulesync/rules/frontend-forms.md +32 -0
  13. package/templates/marketplace/.rulesync/rules/frontend-notifications.md +24 -0
  14. package/templates/marketplace/.rulesync/rules/frontend-povio-components.md +42 -0
  15. package/templates/marketplace/.rulesync/rules/frontend-povio-ui.md +45 -0
  16. package/templates/marketplace/.rulesync/rules/frontend-query-autocomplete.md +29 -0
  17. package/templates/marketplace/.rulesync/rules/frontend-tables-and-lists.md +34 -0
  18. package/templates/marketplace/.rulesync/rules/frontend-translations.md +26 -0
  19. package/templates/marketplace/.rulesync/rules/project-overview.md +32 -0
  20. package/templates/marketplace/.rulesync/rules/robodev-api.md +30 -0
  21. package/templates/marketplace/.rulesync/rules/robodev-auth.md +40 -0
  22. package/templates/marketplace/.rulesync/rules/robodev-database.md +22 -0
  23. package/templates/marketplace/.rulesync/rules/role-based-app-structure.md +36 -0
  24. package/templates/marketplace/.rulesync/skills/media-feature/SKILL.md +21 -0
  25. package/templates/marketplace/.rulesync/skills/povio-ui-styling/SKILL.md +208 -0
  26. package/templates/marketplace/.rulesync/skills/povio-ui-styling/agents/openai.yaml +4 -0
  27. package/templates/marketplace/.rulesync/skills/robodev-api-route/SKILL.md +13 -0
  28. package/templates/marketplace/.rulesync/skills/robodev-table/SKILL.md +12 -0
  29. package/templates/marketplace/README.md +40 -0
  30. package/templates/marketplace/api/_lib.ts +677 -0
  31. package/templates/marketplace/api/cart/[id].ts +51 -0
  32. package/templates/marketplace/api/cart.ts +70 -0
  33. package/templates/marketplace/api/categories.ts +11 -0
  34. package/templates/marketplace/api/checkout.ts +157 -0
  35. package/templates/marketplace/api/health.ts +7 -0
  36. package/templates/marketplace/api/listings/[id].ts +101 -0
  37. package/templates/marketplace/api/listings/paginate.ts +29 -0
  38. package/templates/marketplace/api/listings.ts +90 -0
  39. package/templates/marketplace/api/me.ts +14 -0
  40. package/templates/marketplace/api/orders/[id]/complete.ts +27 -0
  41. package/templates/marketplace/api/orders/[id]/ship.ts +24 -0
  42. package/templates/marketplace/api/orders/[id].ts +15 -0
  43. package/templates/marketplace/api/purchases.ts +19 -0
  44. package/templates/marketplace/api/reviews.ts +58 -0
  45. package/templates/marketplace/api/sales.ts +19 -0
  46. package/templates/marketplace/api/watches/[listingId].ts +18 -0
  47. package/templates/marketplace/api/watches.ts +51 -0
  48. package/templates/marketplace/apps/fe/index.html +24 -0
  49. package/templates/marketplace/apps/fe/openapi-codegen.config.ts +72 -0
  50. package/templates/marketplace/apps/fe/package.json +84 -0
  51. package/templates/marketplace/apps/fe/public/apple-touch-icon.png +0 -0
  52. package/templates/marketplace/apps/fe/public/favicon-96x96.png +0 -0
  53. package/templates/marketplace/apps/fe/public/favicon.ico +0 -0
  54. package/templates/marketplace/apps/fe/public/favicon.svg +3 -0
  55. package/templates/marketplace/apps/fe/public/site.webmanifest +21 -0
  56. package/templates/marketplace/apps/fe/public/web-app-manifest-192x192.png +0 -0
  57. package/templates/marketplace/apps/fe/public/web-app-manifest-512x512.png +0 -0
  58. package/templates/marketplace/apps/fe/src/assets/fonts/GeneralSans-Bold.otf +0 -0
  59. package/templates/marketplace/apps/fe/src/assets/fonts/GeneralSans-Medium.otf +0 -0
  60. package/templates/marketplace/apps/fe/src/assets/fonts/GeneralSans-Regular.otf +0 -0
  61. package/templates/marketplace/apps/fe/src/assets/fonts/GeneralSans-Semibold.otf +0 -0
  62. package/templates/marketplace/apps/fe/src/assets/locales/en/translation.json +335 -0
  63. package/templates/marketplace/apps/fe/src/assets/locales/sl/translation.json +335 -0
  64. package/templates/marketplace/apps/fe/src/clients/app-rest-client.ts +15 -0
  65. package/templates/marketplace/apps/fe/src/clients/auth-token-store.ts +101 -0
  66. package/templates/marketplace/apps/fe/src/clients/rest/app-error-handler.ts +31 -0
  67. package/templates/marketplace/apps/fe/src/clients/rest/interceptors/authorization-header.interceptor.ts +15 -0
  68. package/templates/marketplace/apps/fe/src/clients/rest/interceptors/refresh-token.interceptor.ts +37 -0
  69. package/templates/marketplace/apps/fe/src/clients/rest/interceptors/response.interceptor.ts +17 -0
  70. package/templates/marketplace/apps/fe/src/components/404.tsx +18 -0
  71. package/templates/marketplace/apps/fe/src/components/features/auth/AuthBrandPanel.tsx +60 -0
  72. package/templates/marketplace/apps/fe/src/components/features/auth/AuthLayout.tsx +23 -0
  73. package/templates/marketplace/apps/fe/src/components/features/auth/LoginPage.tsx +111 -0
  74. package/templates/marketplace/apps/fe/src/components/features/auth/RegisterPage.tsx +143 -0
  75. package/templates/marketplace/apps/fe/src/components/features/marketplace/BrowsePage.tsx +76 -0
  76. package/templates/marketplace/apps/fe/src/components/features/marketplace/CartPage.tsx +88 -0
  77. package/templates/marketplace/apps/fe/src/components/features/marketplace/CheckoutPage.tsx +193 -0
  78. package/templates/marketplace/apps/fe/src/components/features/marketplace/ListingCard.tsx +50 -0
  79. package/templates/marketplace/apps/fe/src/components/features/marketplace/ListingDetailsPage.tsx +152 -0
  80. package/templates/marketplace/apps/fe/src/components/features/marketplace/ListingFormPage.tsx +243 -0
  81. package/templates/marketplace/apps/fe/src/components/features/marketplace/MyListingsPage.tsx +84 -0
  82. package/templates/marketplace/apps/fe/src/components/features/marketplace/OrdersPage.tsx +224 -0
  83. package/templates/marketplace/apps/fe/src/components/features/marketplace/WatchlistPage.tsx +56 -0
  84. package/templates/marketplace/apps/fe/src/components/features/profile/ProfilePage.tsx +96 -0
  85. package/templates/marketplace/apps/fe/src/components/googleAnalytics/GoogleAnalytics.tsx +35 -0
  86. package/templates/marketplace/apps/fe/src/components/layout/AppLayout.tsx +19 -0
  87. package/templates/marketplace/apps/fe/src/components/layout/app-header/AppHeader.tsx +95 -0
  88. package/templates/marketplace/apps/fe/src/components/layout/app-header/MobileNavigation.tsx +55 -0
  89. package/templates/marketplace/apps/fe/src/components/layout/app-header/NavLink.tsx +29 -0
  90. package/templates/marketplace/apps/fe/src/components/shared/branding/BrandLogo.tsx +13 -0
  91. package/templates/marketplace/apps/fe/src/components/shared/error/ErrorFallback.tsx +43 -0
  92. package/templates/marketplace/apps/fe/src/components/shared/error/ErrorText.tsx +20 -0
  93. package/templates/marketplace/apps/fe/src/components/shared/error/NotFound.tsx +36 -0
  94. package/templates/marketplace/apps/fe/src/components/shared/forms/RequiredLabel.tsx +21 -0
  95. package/templates/marketplace/apps/fe/src/components/shared/forms/RowInputWrapper.tsx +50 -0
  96. package/templates/marketplace/apps/fe/src/components/shared/head/AppHead.tsx +32 -0
  97. package/templates/marketplace/apps/fe/src/components/shared/head/DefaultAppHead.tsx +34 -0
  98. package/templates/marketplace/apps/fe/src/components/shared/layout/LoadingState.tsx +9 -0
  99. package/templates/marketplace/apps/fe/src/components/shared/layout/ThinPageWrapper.tsx +5 -0
  100. package/templates/marketplace/apps/fe/src/components/shared/page/PageHeader.tsx +69 -0
  101. package/templates/marketplace/apps/fe/src/components/shared/ui/Card.tsx +60 -0
  102. package/templates/marketplace/apps/fe/src/components/shared/ui/GoogleLoginButton.tsx +19 -0
  103. package/templates/marketplace/apps/fe/src/components/shared/ui/RequiredLabel.tsx +22 -0
  104. package/templates/marketplace/apps/fe/src/components/shared/ui/TableActions.tsx +22 -0
  105. package/templates/marketplace/apps/fe/src/config/app.config.ts +35 -0
  106. package/templates/marketplace/apps/fe/src/config/i18n.ts +43 -0
  107. package/templates/marketplace/apps/fe/src/config/inits/a11y.ts +14 -0
  108. package/templates/marketplace/apps/fe/src/config/inits/logger.ts +7 -0
  109. package/templates/marketplace/apps/fe/src/config/inits/sentry.ts +21 -0
  110. package/templates/marketplace/apps/fe/src/config/jwt.config.ts +2 -0
  111. package/templates/marketplace/apps/fe/src/config/query.config.ts +20 -0
  112. package/templates/marketplace/apps/fe/src/hooks/useAuth.ts +5 -0
  113. package/templates/marketplace/apps/fe/src/main.tsx +52 -0
  114. package/templates/marketplace/apps/fe/src/pages/(guest)/login.tsx +23 -0
  115. package/templates/marketplace/apps/fe/src/pages/(guest)/register.tsx +23 -0
  116. package/templates/marketplace/apps/fe/src/pages/(guest)/route.tsx +18 -0
  117. package/templates/marketplace/apps/fe/src/pages/(private)/cart.tsx +22 -0
  118. package/templates/marketplace/apps/fe/src/pages/(private)/checkout.tsx +22 -0
  119. package/templates/marketplace/apps/fe/src/pages/(private)/index.tsx +22 -0
  120. package/templates/marketplace/apps/fe/src/pages/(private)/listings/$id/index.tsx +37 -0
  121. package/templates/marketplace/apps/fe/src/pages/(private)/my-listings.tsx +22 -0
  122. package/templates/marketplace/apps/fe/src/pages/(private)/orders/$id.tsx +40 -0
  123. package/templates/marketplace/apps/fe/src/pages/(private)/orders/index.tsx +22 -0
  124. package/templates/marketplace/apps/fe/src/pages/(private)/profile.tsx +23 -0
  125. package/templates/marketplace/apps/fe/src/pages/(private)/route.tsx +18 -0
  126. package/templates/marketplace/apps/fe/src/pages/(private)/sales.tsx +22 -0
  127. package/templates/marketplace/apps/fe/src/pages/(private)/sell/$id.tsx +44 -0
  128. package/templates/marketplace/apps/fe/src/pages/(private)/sell/index.tsx +19 -0
  129. package/templates/marketplace/apps/fe/src/pages/(private)/watchlist.tsx +22 -0
  130. package/templates/marketplace/apps/fe/src/pages/(public)/auth.tsx +37 -0
  131. package/templates/marketplace/apps/fe/src/pages/(public)/route.tsx +9 -0
  132. package/templates/marketplace/apps/fe/src/pages/__root.tsx +164 -0
  133. package/templates/marketplace/apps/fe/src/providers/AppErrorBoundary.tsx +10 -0
  134. package/templates/marketplace/apps/fe/src/providers/OpenApiRuntimeProvider.tsx +31 -0
  135. package/templates/marketplace/apps/fe/src/providers/index.tsx +44 -0
  136. package/templates/marketplace/apps/fe/src/providers/jwt.provider.tsx +95 -0
  137. package/templates/marketplace/apps/fe/src/routeTree.gen.ts +435 -0
  138. package/templates/marketplace/apps/fe/src/styles/base.css +103 -0
  139. package/templates/marketplace/apps/fe/src/styles/fonts/fonts.tsx +10 -0
  140. package/templates/marketplace/apps/fe/src/styles/fonts/general-sans.css +31 -0
  141. package/templates/marketplace/apps/fe/src/styles/globals.css +28 -0
  142. package/templates/marketplace/apps/fe/src/styles/overrides/defaults/button.override.ts +536 -0
  143. package/templates/marketplace/apps/fe/src/styles/overrides/defaults/checkbox.override.ts +71 -0
  144. package/templates/marketplace/apps/fe/src/styles/overrides/defaults/input.override.ts +252 -0
  145. package/templates/marketplace/apps/fe/src/styles/overrides/defaults/label.override.ts +91 -0
  146. package/templates/marketplace/apps/fe/src/styles/overrides/defaults/modal.override.ts +57 -0
  147. package/templates/marketplace/apps/fe/src/styles/overrides/defaults/radio.override.ts +46 -0
  148. package/templates/marketplace/apps/fe/src/styles/overrides/defaults/table.override.ts +104 -0
  149. package/templates/marketplace/apps/fe/src/styles/overrides/defaults/tag.override.ts +66 -0
  150. package/templates/marketplace/apps/fe/src/styles/overrides/defaults/typography.override.ts +115 -0
  151. package/templates/marketplace/apps/fe/src/styles/overrides/outline.clsx.ts +10 -0
  152. package/templates/marketplace/apps/fe/src/styles/overrides/uiOverrides.override.ts +60 -0
  153. package/templates/marketplace/apps/fe/src/styles/theme.css +2177 -0
  154. package/templates/marketplace/apps/fe/src/types/i18next.d.ts +12 -0
  155. package/templates/marketplace/apps/fe/src/types/table.d.ts +17 -0
  156. package/templates/marketplace/apps/fe/src/types/ui.d.ts +26 -0
  157. package/templates/marketplace/apps/fe/src/types/vite-env.d.ts +20 -0
  158. package/templates/marketplace/apps/fe/src/utils/date.utils.ts +17 -0
  159. package/templates/marketplace/apps/fe/src/utils/image-fallback.ts +9 -0
  160. package/templates/marketplace/apps/fe/src/utils/listing-form.test.ts +69 -0
  161. package/templates/marketplace/apps/fe/src/utils/listing-form.ts +77 -0
  162. package/templates/marketplace/apps/fe/src/utils/listing-submit.ts +29 -0
  163. package/templates/marketplace/apps/fe/src/utils/number.utils.ts +12 -0
  164. package/templates/marketplace/apps/fe/src/utils/string.utils.ts +5 -0
  165. package/templates/marketplace/apps/fe/src/vite-env.d.ts +1 -0
  166. package/templates/marketplace/apps/fe/tsconfig.app.json +32 -0
  167. package/templates/marketplace/apps/fe/tsconfig.json +9 -0
  168. package/templates/marketplace/apps/fe/tsconfig.node.json +31 -0
  169. package/templates/marketplace/apps/fe/vite.config.ts +125 -0
  170. package/templates/marketplace/database.ts +154 -0
  171. package/templates/marketplace/openapi.json +2303 -0
  172. package/templates/marketplace/oxfmt.config.js +23 -0
  173. package/templates/marketplace/package.json +18 -0
  174. package/templates/marketplace/rulesync.jsonc +18 -0
  175. package/templates/marketplace/tsconfig.json +11 -0
  176. package/templates/space/package.json +1 -1
@@ -0,0 +1,152 @@
1
+ import { Button, TextInput, Typography, useToast } from "@povio/ui/tanstack";
2
+ import { useQueryClient } from "@tanstack/react-query";
3
+ import { useState } from "react";
4
+ import { useTranslation } from "react-i18next";
5
+
6
+ import { PageHeader } from "@/components/shared/page/PageHeader";
7
+ import { Card } from "@/components/shared/ui/Card";
8
+ import { useAuth } from "@/hooks/useAuth";
9
+ import { CartQueries } from "@/openapi/cart/cart.queries";
10
+ import { ListingQueries } from "@/openapi/listing/listing.queries";
11
+ import type { ListingModels } from "@/openapi/listing/listing.models";
12
+ import { ReviewQueries } from "@/openapi/review/review.queries";
13
+ import { WatchQueries } from "@/openapi/watch/watch.queries";
14
+ import { getFallbackImageUrl } from "@/utils/image-fallback";
15
+ import { formatCents } from "@/utils/listing-form";
16
+
17
+ interface ListingDetailsPageProps {
18
+ listing: ListingModels.ListingDto;
19
+ }
20
+
21
+ export function ListingDetailsPage({ listing }: ListingDetailsPageProps) {
22
+ const { t } = useTranslation();
23
+ const { user } = useAuth();
24
+ const queryClient = useQueryClient();
25
+ const { successToast, errorToast } = useToast();
26
+ const [qty, setQty] = useState("1");
27
+ const addToCart = CartQueries.useCreate();
28
+ const watch = WatchQueries.useCreate();
29
+ const unwatch = WatchQueries.useDeleteApiWatchesByListingId();
30
+ const { data: reviews } = ReviewQueries.useGetAll({ listingId: listing.id });
31
+ const isOwn = user?.id === listing.sellerId;
32
+ const canBuy = !isOwn && listing.status === "active" && listing.quantity > 0;
33
+ const imageSrc = listing.images[0]?.url ?? getFallbackImageUrl({ width: 800, height: 450 });
34
+
35
+ const onAddToCart = async () => {
36
+ try {
37
+ await addToCart.mutateAsync({ data: { listingId: listing.id, quantity: Number(qty) || 1 } });
38
+ await queryClient.invalidateQueries({ queryKey: CartQueries.keys.all });
39
+ successToast({ text: t(($) => $.listing.addedToCart) });
40
+ } catch {
41
+ errorToast({ text: t(($) => $.listing.addToCartError) });
42
+ }
43
+ };
44
+
45
+ const onToggleWatch = async () => {
46
+ try {
47
+ if (listing.watchedByMe) {
48
+ await unwatch.mutateAsync({ listingId: listing.id });
49
+ } else {
50
+ await watch.mutateAsync({ data: { listingId: listing.id } });
51
+ }
52
+ await queryClient.invalidateQueries({ queryKey: ListingQueries.keys.all });
53
+ await queryClient.invalidateQueries({ queryKey: WatchQueries.keys.all });
54
+ } catch {
55
+ errorToast({ text: t(($) => $.listing.watchError) });
56
+ }
57
+ };
58
+
59
+ return (
60
+ <div className="flex flex-col gap-6">
61
+ <PageHeader enableBack backProps={{ backLink: { to: "/" } }} title={listing.title} />
62
+
63
+ <Card className="max-w-3xl overflow-hidden p-0">
64
+ <div className="aspect-video w-full bg-elevation-fill-default-2">
65
+ <img src={imageSrc} alt="" className="h-full w-full object-cover" />
66
+ </div>
67
+ <div className="flex flex-col gap-4 p-4">
68
+ <Typography size="title-5" variant="prominent-1">
69
+ {formatCents(listing.priceCents)}
70
+ </Typography>
71
+ {listing.description ? (
72
+ <Typography size="body-3" className="whitespace-pre-wrap text-text-default-2">
73
+ {listing.description}
74
+ </Typography>
75
+ ) : null}
76
+ <Typography size="label-3" className="text-text-default-2">
77
+ {t(($) => $.listing.seller)}: {listing.sellerName || listing.sellerEmail}
78
+ </Typography>
79
+ {listing.category ? (
80
+ <Typography size="label-3" className="text-text-default-2">
81
+ {t(($) => $.listing.category)}: {listing.category.name}
82
+ </Typography>
83
+ ) : null}
84
+ <Typography size="label-3" className="text-text-default-2">
85
+ {t(($) => $.listing.shipping)}: {formatCents(listing.shippingCents)} ·{" "}
86
+ {t(($) => $.listing.shippingDays, { count: listing.shippingDays })}
87
+ </Typography>
88
+ <Typography size="label-3" className="text-text-default-2">
89
+ {listing.quantity > 0
90
+ ? t(($) => $.listing.inStock, { count: listing.quantity })
91
+ : t(($) => $.listing.soldOut)}
92
+ </Typography>
93
+ <Typography size="label-3" className="text-text-default-2">
94
+ {listing.sellerAverageRating != null
95
+ ? t(($) => $.listing.rating, { rating: listing.sellerAverageRating })
96
+ : t(($) => $.listing.noRating)}
97
+ </Typography>
98
+
99
+ {isOwn ? <Typography size="body-3">{t(($) => $.listing.ownListing)}</Typography> : null}
100
+
101
+ {canBuy ? (
102
+ <div className="flex flex-wrap items-end gap-2">
103
+ <TextInput
104
+ variant="filled"
105
+ size="extra-small"
106
+ value={qty}
107
+ onChange={setQty}
108
+ label={t(($) => $.listing.quantity)}
109
+ />
110
+ <Button size="xs" isLoading={addToCart.isPending} onPress={() => void onAddToCart()}>
111
+ {t(($) => $.listing.addToCart)}
112
+ </Button>
113
+ </div>
114
+ ) : null}
115
+
116
+ {!isOwn ? (
117
+ <Button
118
+ size="xs"
119
+ variant="outlined"
120
+ color="secondary"
121
+ onPress={() => void onToggleWatch()}
122
+ >
123
+ {listing.watchedByMe ? t(($) => $.listing.unwatch) : t(($) => $.listing.watch)}
124
+ </Button>
125
+ ) : (
126
+ <Button size="xs" link={{ to: "/sell/$id", params: { id: listing.id } }}>
127
+ {t(($) => $.sell.edit)}
128
+ </Button>
129
+ )}
130
+ </div>
131
+ </Card>
132
+
133
+ <div className="flex max-w-3xl flex-col gap-3">
134
+ <Typography size="title-5" variant="prominent-1">
135
+ {t(($) => $.listing.reviews)}
136
+ </Typography>
137
+ {!reviews || reviews.length === 0 ? (
138
+ <Typography size="body-3" className="text-text-default-2">
139
+ {t(($) => $.listing.noReviews)}
140
+ </Typography>
141
+ ) : (
142
+ reviews.map((review) => (
143
+ <Card key={review.id}>
144
+ <Typography size="label-3">{review.rating}/5</Typography>
145
+ {review.body ? <Typography size="body-3">{review.body}</Typography> : null}
146
+ </Card>
147
+ ))
148
+ )}
149
+ </div>
150
+ </div>
151
+ );
152
+ }
@@ -0,0 +1,243 @@
1
+ import {
2
+ Button,
3
+ FileUpload,
4
+ TextArea,
5
+ TextInput,
6
+ Typography,
7
+ useForm,
8
+ useFormValue,
9
+ useToast,
10
+ } from "@povio/ui/tanstack";
11
+ import { useQueryClient } from "@tanstack/react-query";
12
+ import { useNavigate } from "@tanstack/react-router";
13
+ import { useState } from "react";
14
+ import { useTranslation } from "react-i18next";
15
+ import { z } from "zod";
16
+
17
+ import { RowInputWrapper } from "@/components/shared/forms/RowInputWrapper";
18
+ import { PageHeader } from "@/components/shared/page/PageHeader";
19
+ import { CategoryQueries } from "@/openapi/category/category.queries";
20
+ import { ListingQueries } from "@/openapi/listing/listing.queries";
21
+ import type { ListingModels } from "@/openapi/listing/listing.models";
22
+ import { bindLocalListingImages, centsToDollarsInput, dollarsToCents } from "@/utils/listing-form";
23
+ import { createListing, updateListing } from "@/utils/listing-submit";
24
+
25
+ const listingFormSchema = z.object({
26
+ title: z.string().min(1),
27
+ description: z.string().optional(),
28
+ categoryId: z.string().min(1),
29
+ price: z.string().min(1),
30
+ quantity: z.string().min(1),
31
+ shipping: z.string().min(1),
32
+ shippingDays: z.string().min(1),
33
+ });
34
+
35
+ interface ListingFormPageProps {
36
+ listing?: ListingModels.ListingDto;
37
+ }
38
+
39
+ export function ListingFormPage({ listing }: ListingFormPageProps) {
40
+ const { t } = useTranslation();
41
+ const navigate = useNavigate();
42
+ const queryClient = useQueryClient();
43
+ const { successToast, errorToast } = useToast();
44
+ const { data: categories } = CategoryQueries.useGetAll();
45
+ const [pickedFiles, setPickedFiles] = useState<File[]>([]);
46
+ const [removedIds, setRemovedIds] = useState<string[]>([]);
47
+ const [isPending, setIsPending] = useState(false);
48
+ const remainingImages = (listing?.images ?? []).filter((image) => !removedIds.includes(image.id));
49
+
50
+ const form = useForm({
51
+ zodSchema: listingFormSchema,
52
+ defaultValues: {
53
+ title: listing?.title ?? "",
54
+ description: listing?.description ?? "",
55
+ categoryId: listing?.categoryId ?? "",
56
+ price: listing ? centsToDollarsInput(listing.priceCents) : "",
57
+ quantity: listing ? String(listing.quantity) : "1",
58
+ shipping: listing ? centsToDollarsInput(listing.shippingCents) : "",
59
+ shippingDays: listing ? String(listing.shippingDays) : "3",
60
+ },
61
+ });
62
+ const categoryId = useFormValue(form, (values) => values.categoryId);
63
+
64
+ const onSubmit = async (data: z.infer<typeof listingFormSchema>) => {
65
+ try {
66
+ setIsPending(true);
67
+ const fields = {
68
+ title: data.title,
69
+ description: data.description,
70
+ categoryId: data.categoryId,
71
+ priceCents: dollarsToCents(data.price),
72
+ quantity: Number(data.quantity),
73
+ shippingCents: dollarsToCents(data.shipping),
74
+ shippingDays: Number(data.shippingDays),
75
+ files: pickedFiles,
76
+ removeImageIds: removedIds,
77
+ };
78
+ if (listing) {
79
+ await updateListing(listing.id, fields);
80
+ successToast({ text: t(($) => $.listingForm.updateSuccess) });
81
+ } else {
82
+ await createListing(fields);
83
+ successToast({ text: t(($) => $.listingForm.createSuccess) });
84
+ }
85
+ await queryClient.invalidateQueries({ queryKey: ListingQueries.keys.all });
86
+ await navigate({ to: "/my-listings" });
87
+ } catch {
88
+ errorToast({
89
+ text: listing ? t(($) => $.listingForm.updateError) : t(($) => $.listingForm.createError),
90
+ });
91
+ } finally {
92
+ setIsPending(false);
93
+ }
94
+ };
95
+
96
+ return (
97
+ <div className="flex flex-col gap-6">
98
+ <PageHeader
99
+ enableBack
100
+ backProps={{ backLink: { to: "/my-listings" } }}
101
+ title={listing ? t(($) => $.listingForm.editTitle) : t(($) => $.listingForm.createTitle)}
102
+ />
103
+
104
+ <form onSubmit={form.handleSubmit(onSubmit)} className="flex max-w-xl flex-col gap-4">
105
+ <RowInputWrapper label={t(($) => $.listingForm.title)} isRequired>
106
+ <TextInput
107
+ variant="filled"
108
+ size="extra-small"
109
+ field={{ form, name: "title" }}
110
+ label={t(($) => $.listingForm.title)}
111
+ placeholder={t(($) => $.listingForm.titlePlaceholder)}
112
+ hideLabel
113
+ isRequired
114
+ />
115
+ </RowInputWrapper>
116
+
117
+ <RowInputWrapper label={t(($) => $.listingForm.description)}>
118
+ <TextArea
119
+ variant="filled"
120
+ size="extra-small"
121
+ field={{ form, name: "description" }}
122
+ label={t(($) => $.listingForm.description)}
123
+ placeholder={t(($) => $.listingForm.descriptionPlaceholder)}
124
+ hideLabel
125
+ />
126
+ </RowInputWrapper>
127
+
128
+ <RowInputWrapper label={t(($) => $.listingForm.category)} isRequired>
129
+ <div className="flex flex-wrap gap-1">
130
+ {(categories ?? []).map((category) => (
131
+ <Button
132
+ key={category.id}
133
+ type="button"
134
+ size="xs"
135
+ variant={categoryId === category.id ? "contained" : "outlined"}
136
+ color={categoryId === category.id ? "primary" : "secondary"}
137
+ onPress={() => form.setFieldValue("categoryId", category.id)}
138
+ >
139
+ {category.name}
140
+ </Button>
141
+ ))}
142
+ </div>
143
+ </RowInputWrapper>
144
+
145
+ <RowInputWrapper label={t(($) => $.listingForm.price)} isRequired>
146
+ <TextInput
147
+ variant="filled"
148
+ size="extra-small"
149
+ field={{ form, name: "price" }}
150
+ label={t(($) => $.listingForm.price)}
151
+ hideLabel
152
+ isRequired
153
+ />
154
+ </RowInputWrapper>
155
+
156
+ <RowInputWrapper label={t(($) => $.listingForm.quantity)} isRequired>
157
+ <TextInput
158
+ variant="filled"
159
+ size="extra-small"
160
+ field={{ form, name: "quantity" }}
161
+ label={t(($) => $.listingForm.quantity)}
162
+ hideLabel
163
+ isRequired
164
+ />
165
+ </RowInputWrapper>
166
+
167
+ <RowInputWrapper label={t(($) => $.listingForm.shipping)} isRequired>
168
+ <TextInput
169
+ variant="filled"
170
+ size="extra-small"
171
+ field={{ form, name: "shipping" }}
172
+ label={t(($) => $.listingForm.shipping)}
173
+ hideLabel
174
+ isRequired
175
+ />
176
+ </RowInputWrapper>
177
+
178
+ <RowInputWrapper label={t(($) => $.listingForm.shippingDays)} isRequired>
179
+ <TextInput
180
+ variant="filled"
181
+ size="extra-small"
182
+ field={{ form, name: "shippingDays" }}
183
+ label={t(($) => $.listingForm.shippingDays)}
184
+ hideLabel
185
+ isRequired
186
+ />
187
+ </RowInputWrapper>
188
+
189
+ {remainingImages.length > 0 ? (
190
+ <div className="flex flex-wrap gap-2">
191
+ {remainingImages.map((image) => (
192
+ <div key={image.id} className="flex flex-col gap-1">
193
+ <img src={image.url} alt="" className="h-20 w-20 object-cover" />
194
+ <Button
195
+ type="button"
196
+ size="xs"
197
+ variant="outlined"
198
+ color="secondary"
199
+ onPress={() => setRemovedIds((current) => [...current, image.id])}
200
+ >
201
+ {t(($) => $.listingForm.removeImage)}
202
+ </Button>
203
+ </div>
204
+ ))}
205
+ </div>
206
+ ) : null}
207
+
208
+ {pickedFiles.length > 0 ? (
209
+ <Typography size="label-3" className="text-text-default-2">
210
+ {pickedFiles.map((file) => file.name).join(", ")}
211
+ </Typography>
212
+ ) : null}
213
+
214
+ <FileUpload
215
+ label={t(($) => $.listingForm.images)}
216
+ emptyText={t(($) => $.listingForm.imageEmptyText)}
217
+ uploadText={t(($) => $.listingForm.imageUploadText)}
218
+ browseText={t(($) => $.listingForm.imageBrowseText)}
219
+ acceptedFileTypes={["image/jpeg", "image/png", "image/webp"]}
220
+ allowsMultiple
221
+ {...bindLocalListingImages((file) =>
222
+ setPickedFiles((current) => [...current, file].slice(0, 8)),
223
+ )}
224
+ />
225
+
226
+ <div className="flex justify-end gap-2">
227
+ <Button
228
+ type="button"
229
+ variant="outlined"
230
+ color="secondary"
231
+ size="xs"
232
+ onPress={() => navigate({ to: "/my-listings" })}
233
+ >
234
+ {t(($) => $.listingForm.cancel)}
235
+ </Button>
236
+ <Button type="submit" size="xs" isLoading={isPending} isDisabled={isPending}>
237
+ {listing ? t(($) => $.listingForm.submitEdit) : t(($) => $.listingForm.submitCreate)}
238
+ </Button>
239
+ </div>
240
+ </form>
241
+ </div>
242
+ );
243
+ }
@@ -0,0 +1,84 @@
1
+ import { Button, Typography, useToast } from "@povio/ui/tanstack";
2
+ import { useQueryClient } from "@tanstack/react-query";
3
+ import { Plus } from "lucide-react";
4
+ import { useTranslation } from "react-i18next";
5
+
6
+ import { LoadingState } from "@/components/shared/layout/LoadingState";
7
+ import { PageHeader } from "@/components/shared/page/PageHeader";
8
+ import { ListingQueries } from "@/openapi/listing/listing.queries";
9
+ import { formatCents } from "@/utils/listing-form";
10
+
11
+ import { ListingCard } from "./ListingCard";
12
+
13
+ export function MyListingsPage() {
14
+ const { t } = useTranslation();
15
+ const queryClient = useQueryClient();
16
+ const { successToast, errorToast } = useToast();
17
+ const { data, isLoading } = ListingQueries.useGetAll({ mine: "true" });
18
+ const deactivate = ListingQueries.useDeleteApiListingsById();
19
+ const listings = data ?? [];
20
+
21
+ const onDeactivate = async (id: string) => {
22
+ try {
23
+ await deactivate.mutateAsync({ id });
24
+ await queryClient.invalidateQueries({ queryKey: ListingQueries.keys.all });
25
+ successToast({ text: t(($) => $.sell.deactivateSuccess) });
26
+ } catch {
27
+ errorToast({ text: t(($) => $.sell.deactivateError) });
28
+ }
29
+ };
30
+
31
+ return (
32
+ <div className="flex flex-col gap-6">
33
+ <PageHeader
34
+ title={t(($) => $.sell.title)}
35
+ actions={
36
+ <Button size="xs" icon={Plus} link={{ to: "/sell" }}>
37
+ {t(($) => $.sell.create)}
38
+ </Button>
39
+ }
40
+ />
41
+
42
+ {isLoading ? (
43
+ <LoadingState />
44
+ ) : listings.length === 0 ? (
45
+ <Typography size="body-3" className="text-text-default-2">
46
+ {t(($) => $.sell.empty)}
47
+ </Typography>
48
+ ) : (
49
+ <div className="flex flex-col gap-4">
50
+ {listings.map((listing) => (
51
+ <div key={listing.id} className="flex flex-col gap-2">
52
+ <ListingCard listing={listing} />
53
+ <div className="flex flex-wrap items-center gap-2">
54
+ <Typography size="label-3" className="text-text-default-2">
55
+ {formatCents(listing.priceCents)}
56
+ {listing.quantity <= 0 ? ` · ${t(($) => $.sell.soldOut)}` : ""}
57
+ {listing.status === "inactive" ? ` · ${t(($) => $.sell.inactive)}` : ""}
58
+ </Typography>
59
+ <Button
60
+ size="xs"
61
+ variant="outlined"
62
+ color="secondary"
63
+ link={{ to: "/sell/$id", params: { id: listing.id } }}
64
+ >
65
+ {t(($) => $.sell.edit)}
66
+ </Button>
67
+ {listing.status === "active" ? (
68
+ <Button
69
+ size="xs"
70
+ variant="outlined"
71
+ color="secondary"
72
+ onPress={() => void onDeactivate(listing.id)}
73
+ >
74
+ {t(($) => $.sell.deactivate)}
75
+ </Button>
76
+ ) : null}
77
+ </div>
78
+ </div>
79
+ ))}
80
+ </div>
81
+ )}
82
+ </div>
83
+ );
84
+ }