@orunelle/theme-engine 0.0.0-stage → 2.0.0-alpha.13
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.
- package/dist/commerce/account.d.ts +4 -0
- package/dist/commerce/account.d.ts.map +1 -0
- package/dist/commerce/account.js +198 -0
- package/dist/commerce/cart.d.ts +6 -0
- package/dist/commerce/cart.d.ts.map +1 -0
- package/dist/commerce/cart.js +66 -0
- package/dist/commerce/checkout.d.ts +4 -0
- package/dist/commerce/checkout.d.ts.map +1 -0
- package/dist/commerce/checkout.js +152 -0
- package/dist/commerce/orders.d.ts +8 -0
- package/dist/commerce/orders.d.ts.map +1 -0
- package/dist/commerce/orders.js +19 -0
- package/dist/commerce/public-pages.d.ts +17 -0
- package/dist/commerce/public-pages.d.ts.map +1 -0
- package/dist/commerce/public-pages.js +19 -0
- package/dist/commerce/shared.d.ts +31 -0
- package/dist/commerce/shared.d.ts.map +1 -0
- package/dist/commerce/shared.js +81 -0
- package/dist/commerce-pages.d.ts +5 -0
- package/dist/commerce-pages.d.ts.map +1 -0
- package/dist/commerce-pages.js +4 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +112 -0
- package/dist/library.d.ts +78 -0
- package/dist/library.d.ts.map +1 -0
- package/dist/library.js +277 -0
- package/dist/product.d.ts +77 -0
- package/dist/product.d.ts.map +1 -0
- package/dist/product.js +241 -0
- package/dist/sections.d.ts +48 -0
- package/dist/sections.d.ts.map +1 -0
- package/dist/sections.js +98 -0
- package/package.json +45 -3
- package/sections.css +781 -0
- package/styles.css +1274 -0
- package/README.md +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../src/commerce/account.tsx"],"names":[],"mappings":"AA2fA,wBAAgB,kBAAkB,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,+BA0D5D"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Link, useLocation } from "@tanstack/react-router";
|
|
4
|
+
import { useStorefront, useCommerce, useCustomerQuery, customerCacheKey, } from "@orunelle/theme-sdk";
|
|
5
|
+
import { CommerceError } from "@orunelle/theme-sdk/commerce";
|
|
6
|
+
import { Orders } from "./orders.js";
|
|
7
|
+
import { useCopy, useAction, Failure, Field, Guard, FixtureNotice, values, val, } from "./shared.js";
|
|
8
|
+
function AuthForm({ path }) {
|
|
9
|
+
const context = useStorefront(), session = useCommerce(), action = useAction(), t = useCopy();
|
|
10
|
+
const location = useLocation();
|
|
11
|
+
const title = path === "register"
|
|
12
|
+
? t("Create an account", "إنشاء حساب")
|
|
13
|
+
: path === "forgot-password"
|
|
14
|
+
? t("Forgot your password?", "نسيت كلمة المرور؟")
|
|
15
|
+
: path === "reset-password"
|
|
16
|
+
? t("Reset your password", "إعادة تعيين كلمة المرور")
|
|
17
|
+
: path === "verify-email"
|
|
18
|
+
? t("Verify your email", "تأكيد البريد الإلكتروني")
|
|
19
|
+
: t("Sign in", "تسجيل الدخول");
|
|
20
|
+
const submit = (event) => {
|
|
21
|
+
const data = values(event);
|
|
22
|
+
void action.run(async () => {
|
|
23
|
+
const email = val(data, "email"), password = val(data, "password");
|
|
24
|
+
if (path === "forgot-password") {
|
|
25
|
+
await session.client.customer.requestReset(email);
|
|
26
|
+
action.setNotice(t("If the account is eligible, a recovery link has been queued. Check your email.", "إذا كان الحساب مؤهلًا، سيتم إرسال رابط الاستعادة. تحقق من بريدك."));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (path === "reset-password") {
|
|
30
|
+
if (val(data, "token"))
|
|
31
|
+
await session.client.customer.resetWithToken(val(data, "token"), password);
|
|
32
|
+
else
|
|
33
|
+
await session.client.customer.resetPassword(email, val(data, "code"), password);
|
|
34
|
+
action.setNotice(t("Password updated. You can sign in.", "تم تحديث كلمة المرور. يمكنك تسجيل الدخول."));
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (path === "verify-email") {
|
|
38
|
+
await session.client.customer.verifyEmail(email, val(data, "code"));
|
|
39
|
+
action.setNotice(t("Email verified. You can sign in.", "تم تأكيد البريد. يمكنك تسجيل الدخول."));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const result = path === "register"
|
|
43
|
+
? await session.client.customer.register({
|
|
44
|
+
email,
|
|
45
|
+
password,
|
|
46
|
+
firstName: val(data, "firstName"),
|
|
47
|
+
lastName: val(data, "lastName"),
|
|
48
|
+
phone: val(data, "phone"),
|
|
49
|
+
locale: context.locale === "ar" ? "ar-EG" : "en-US",
|
|
50
|
+
marketingConsent: false,
|
|
51
|
+
})
|
|
52
|
+
: await session.client.customer.login(email, password);
|
|
53
|
+
if (!result.accessToken) {
|
|
54
|
+
action.setNotice(t("Check your email to verify your account before signing in.", "تحقق من بريدك لتأكيد الحساب قبل تسجيل الدخول."));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
await session.acceptToken(result.accessToken);
|
|
58
|
+
try {
|
|
59
|
+
await session.client.cart.mergeGuest();
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
if (!(error instanceof CommerceError && error.code === "NO_GUEST_CART")) {
|
|
63
|
+
action.setNotice(t("Signed in. Your guest cart still needs merging; use Merge guest cart in your account.", "تم تسجيل الدخول. لا تزال سلة الزائر بحاجة للدمج؛ استخدم دمج سلة الزائر في الحساب."));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
action.setNotice(t("Signed in successfully.", "تم تسجيل الدخول بنجاح."));
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
return (_jsxs(_Fragment, { children: [_jsx("h1", { children: title }), context.commerce !== "api" ? (_jsx(FixtureNotice, {})) : (_jsxs("form", { className: "store-form", method: "post", onSubmit: submit, children: [path === "register" && (_jsxs(_Fragment, { children: [_jsx(Field, { name: "firstName", label: t("First name", "الاسم الأول"), autoComplete: "given-name" }), _jsx(Field, { name: "lastName", label: t("Last name", "اسم العائلة"), autoComplete: "family-name" }), _jsx(Field, { name: "phone", type: "tel", label: t("Phone", "الهاتف"), autoComplete: "tel" })] })), _jsx(Field, { name: "email", type: "email", label: t("Email", "البريد الإلكتروني"), autoComplete: "email", required: path !== "reset-password" }), !["forgot-password", "verify-email"].includes(path) && (_jsx(Field, { name: "password", type: "password", label: t("Password", "كلمة المرور"), autoComplete: path === "login" ? "current-password" : "new-password" })), ["reset-password", "verify-email"].includes(path) && (_jsx(Field, { name: "code", label: t("Email code", "رمز البريد الإلكتروني"), required: path !== "reset-password", autoComplete: "one-time-code" })), path === "reset-password" && (_jsx(Field, { name: "token", label: t("Recovery token from your email link", "رمز الاستعادة من رابط البريد"), required: false, value: new URLSearchParams(location.searchStr).get("token") ?? "" })), _jsx("button", { disabled: action.pending || !session.ready, children: action.pending ? t("Please wait…", "يرجى الانتظار…") : title }), _jsx(Failure, { error: action.error }), _jsx("p", { role: "status", children: action.notice })] })), _jsx("nav", { className: "account-links", "aria-label": t("Account options", "خيارات الحساب"), children: [
|
|
71
|
+
"login",
|
|
72
|
+
"register",
|
|
73
|
+
"forgot-password",
|
|
74
|
+
"reset-password",
|
|
75
|
+
"verify-email",
|
|
76
|
+
"account",
|
|
77
|
+
]
|
|
78
|
+
.filter((p) => p !== path)
|
|
79
|
+
.map((p) => (_jsx(Link, { to: `/${context.locale}/${p}`, children: {
|
|
80
|
+
login: t("Sign in", "تسجيل الدخول"),
|
|
81
|
+
register: t("Create account", "إنشاء حساب"),
|
|
82
|
+
"forgot-password": t("Forgot password", "نسيت كلمة المرور"),
|
|
83
|
+
"reset-password": t("Reset password", "إعادة تعيين كلمة المرور"),
|
|
84
|
+
"verify-email": t("Verify email", "تأكيد البريد"),
|
|
85
|
+
account: t("Your account", "حسابك"),
|
|
86
|
+
}[p] }, p))) })] }));
|
|
87
|
+
}
|
|
88
|
+
function Profile() {
|
|
89
|
+
const context = useStorefront(), session = useCommerce(), t = useCopy(), action = useAction();
|
|
90
|
+
const query = useCustomerQuery(customerCacheKey(context, "profile"), session.client.customer.me, session.authenticated);
|
|
91
|
+
return (_jsxs(_Fragment, { children: [_jsx(Failure, { error: query.error || action.error }), query.data && (_jsxs("form", { className: "store-form", method: "post", onSubmit: (event) => {
|
|
92
|
+
const data = values(event);
|
|
93
|
+
void action.run(async () => {
|
|
94
|
+
await session.client.customer.update({
|
|
95
|
+
firstName: val(data, "firstName"),
|
|
96
|
+
lastName: val(data, "lastName"),
|
|
97
|
+
phone: val(data, "phone"),
|
|
98
|
+
});
|
|
99
|
+
await query.refetch();
|
|
100
|
+
action.setNotice(t("Profile saved.", "تم حفظ الملف الشخصي."));
|
|
101
|
+
});
|
|
102
|
+
}, children: [_jsx("p", { children: query.data.email }), _jsx(Field, { name: "firstName", label: t("First name", "الاسم الأول"), value: query.data.firstName }), _jsx(Field, { name: "lastName", label: t("Last name", "اسم العائلة"), value: query.data.lastName }), _jsx(Field, { name: "phone", type: "tel", label: t("Phone", "الهاتف"), value: query.data.phone }), _jsx("button", { disabled: action.pending, children: t("Save profile", "حفظ الملف الشخصي") }), _jsx("p", { role: "status", children: action.notice })] }, query.data.id)), _jsxs("div", { className: "action-row", children: [_jsx("button", { className: "button-secondary", disabled: action.pending, onClick: () => void action.run(async () => {
|
|
103
|
+
await session.client.cart.mergeGuest();
|
|
104
|
+
await session.cache.invalidateQueries();
|
|
105
|
+
action.setNotice(t("Guest cart merged.", "تم دمج سلة الزائر."));
|
|
106
|
+
}), children: t("Merge guest cart", "دمج سلة الزائر") }), _jsx("button", { disabled: action.pending, onClick: () => void action.run(session.logout), children: t("Sign out", "تسجيل الخروج") })] })] }));
|
|
107
|
+
}
|
|
108
|
+
function Addresses() {
|
|
109
|
+
const context = useStorefront(), session = useCommerce(), t = useCopy(), action = useAction();
|
|
110
|
+
const query = useCustomerQuery(customerCacheKey(context, "addresses"), session.client.addresses.list, session.authenticated);
|
|
111
|
+
const [editing, setEditing] = useState();
|
|
112
|
+
const current = query.data?.find((a) => a.id === editing);
|
|
113
|
+
const fields = [
|
|
114
|
+
["label", "Address label", "اسم العنوان", true],
|
|
115
|
+
["recipientName", "Recipient name", "اسم المستلم", true],
|
|
116
|
+
["phone", "Phone", "الهاتف", true],
|
|
117
|
+
["governorate", "Governorate", "المحافظة", true],
|
|
118
|
+
["city", "City", "المدينة", true],
|
|
119
|
+
["district", "District", "المنطقة", false],
|
|
120
|
+
["street", "Street", "الشارع", true],
|
|
121
|
+
["building", "Building", "المبنى", true],
|
|
122
|
+
["floor", "Floor", "الطابق", false],
|
|
123
|
+
["apartment", "Apartment", "الشقة", false],
|
|
124
|
+
["landmark", "Landmark", "علامة مميزة", false],
|
|
125
|
+
["postalCode", "Postal code", "الرمز البريدي", false],
|
|
126
|
+
];
|
|
127
|
+
return (_jsxs(_Fragment, { children: [_jsx(Failure, { error: query.error || action.error }), _jsx("ul", { className: "resource-list", children: query.data?.map((a) => (_jsxs("li", { children: [_jsx("h2", { children: a.label }), _jsx("p", { children: [a.recipientName, a.street, a.city, a.governorate].join(" · ") }), _jsxs("div", { className: "action-row", children: [_jsx("button", { className: "button-secondary", onClick: () => setEditing(a.id), children: t("Edit address", "تعديل العنوان") }), _jsx("button", { className: "button-secondary", disabled: action.pending, onClick: () => void action.run(async () => {
|
|
128
|
+
await session.client.addresses.remove(a.id);
|
|
129
|
+
await query.refetch();
|
|
130
|
+
}), children: t("Remove address", "حذف العنوان") })] })] }, a.id))) }), query.data?.length === 0 && (_jsx("p", { children: t("Add your first delivery address.", "أضف أول عنوان توصيل.") })), _jsx("h2", { className: "form-heading", children: editing
|
|
131
|
+
? t("Edit address", "تعديل العنوان")
|
|
132
|
+
: t("Add an address", "إضافة عنوان") }), _jsxs("form", { className: "store-form", method: "post", onSubmit: (event) => {
|
|
133
|
+
const data = values(event);
|
|
134
|
+
void action.run(async () => {
|
|
135
|
+
const input = Object.fromEntries(fields.map(([key]) => [key, val(data, key)]));
|
|
136
|
+
const payload = {
|
|
137
|
+
...input,
|
|
138
|
+
country: "EG",
|
|
139
|
+
isDefault: data.get("isDefault") === "on",
|
|
140
|
+
};
|
|
141
|
+
if (editing)
|
|
142
|
+
await session.client.addresses.update(editing, payload);
|
|
143
|
+
else
|
|
144
|
+
await session.client.addresses.add(payload);
|
|
145
|
+
setEditing(undefined);
|
|
146
|
+
await query.refetch();
|
|
147
|
+
action.setNotice(t("Address saved.", "تم حفظ العنوان."));
|
|
148
|
+
});
|
|
149
|
+
}, children: [fields.map(([name, en, ar, required]) => (_jsx(Field, { name: name, label: t(en, ar), required: required, value: String(current?.[name] ?? "") }, name))), _jsxs("label", { className: "checkbox-field", children: [_jsx("input", { type: "checkbox", name: "isDefault", defaultChecked: current?.isDefault }), t("Default delivery address", "عنوان التوصيل الافتراضي")] }), _jsx("button", { disabled: action.pending, children: t("Save address", "حفظ العنوان") }), editing && (_jsx("button", { type: "button", className: "button-secondary", onClick: () => setEditing(undefined), children: t("Cancel edit", "إلغاء التعديل") })), _jsx("p", { role: "status", children: action.notice })] }, editing ?? "new")] }));
|
|
150
|
+
}
|
|
151
|
+
function WishlistPage() {
|
|
152
|
+
const context = useStorefront(), session = useCommerce(), t = useCopy(), action = useAction();
|
|
153
|
+
const query = useCustomerQuery(customerCacheKey(context, "wishlist"), session.client.wishlist.read, session.authenticated);
|
|
154
|
+
const items = query.data
|
|
155
|
+
? [
|
|
156
|
+
...query.data.uncategorized,
|
|
157
|
+
...query.data.collections.flatMap((c) => c.items),
|
|
158
|
+
]
|
|
159
|
+
: [];
|
|
160
|
+
return (_jsxs(_Fragment, { children: [_jsx(Failure, { error: query.error || action.error }), _jsx("ul", { className: "resource-list", children: items.map((item) => (_jsxs("li", { children: [item.productVariant ? (_jsx(Link, { to: `/${context.locale}/products/${item.productVariant.product.handle}`, children: item.productVariant.product.name })) : (_jsx("span", { children: t("Unavailable product", "منتج غير متاح") })), _jsx("button", { className: "button-secondary", disabled: action.pending, onClick: () => void action.run(async () => {
|
|
161
|
+
await session.client.wishlist.remove(item.id);
|
|
162
|
+
await query.refetch();
|
|
163
|
+
}), children: t("Remove from wishlist", "حذف من المفضلة") })] }, item.id))) }), query.data && !items.length && (_jsx("p", { className: "empty-state", children: t("Your wishlist is empty. Save a product to find it here.", "المفضلة فارغة. احفظ منتجًا ليظهر هنا.") }))] }));
|
|
164
|
+
}
|
|
165
|
+
function Tracking() {
|
|
166
|
+
const t = useCopy(), [number, setNumber] = useState("");
|
|
167
|
+
return (_jsxs(_Fragment, { children: [_jsxs("form", { className: "store-form", method: "get", onSubmit: (e) => {
|
|
168
|
+
const data = values(e);
|
|
169
|
+
setNumber(val(data, "number"));
|
|
170
|
+
}, children: [_jsx(Field, { name: "number", label: t("Order number", "رقم الطلب") }), _jsx("button", { children: t("Find order", "البحث عن الطلب") })] }), number && _jsx(Orders, { number: number })] }));
|
|
171
|
+
}
|
|
172
|
+
export function DefaultAccountPage({ path }) {
|
|
173
|
+
const context = useStorefront(), t = useCopy();
|
|
174
|
+
if ([
|
|
175
|
+
"login",
|
|
176
|
+
"register",
|
|
177
|
+
"forgot-password",
|
|
178
|
+
"reset-password",
|
|
179
|
+
"verify-email",
|
|
180
|
+
].includes(path))
|
|
181
|
+
return (_jsx("section", { className: "account-page", children: _jsx(AuthForm, { path: path }) }));
|
|
182
|
+
const title = path === "account/addresses"
|
|
183
|
+
? t("Delivery addresses", "عناوين التوصيل")
|
|
184
|
+
: path.startsWith("account/orders")
|
|
185
|
+
? t("Your orders", "طلباتك")
|
|
186
|
+
: path === "account/wishlist"
|
|
187
|
+
? t("Your wishlist", "المفضلة")
|
|
188
|
+
: path === "tracking"
|
|
189
|
+
? t("Track your order", "تتبع طلبك")
|
|
190
|
+
: t("Your account", "حسابك");
|
|
191
|
+
return (_jsxs("section", { className: "account-page", children: [_jsx("h1", { children: title }), _jsx("nav", { className: "account-links", "aria-label": t("Your account", "حسابك"), children: [
|
|
192
|
+
["account", t("Profile", "الملف الشخصي")],
|
|
193
|
+
["account/addresses", t("Addresses", "العناوين")],
|
|
194
|
+
["account/orders", t("Orders", "الطلبات")],
|
|
195
|
+
["account/wishlist", t("Wishlist", "المفضلة")],
|
|
196
|
+
["tracking", t("Tracking", "التتبع")],
|
|
197
|
+
].map(([route, label]) => (_jsx(Link, { to: `/${context.locale}/${route}`, children: label }, route))) }), _jsx(Guard, { children: path === "account/addresses" ? (_jsx(Addresses, {})) : path.startsWith("account/orders") ? (_jsx(Orders, { number: path.split("/")[2] ?? "" })) : path === "account/wishlist" ? (_jsx(WishlistPage, {})) : path === "tracking" ? (_jsx(Tracking, {})) : (_jsx(Profile, {})) })] }));
|
|
198
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Variant } from "@orunelle/theme-sdk/commerce";
|
|
2
|
+
export declare function DefaultProductActions({ variants, }: {
|
|
3
|
+
variants: readonly Variant[];
|
|
4
|
+
}): import("react").JSX.Element | null;
|
|
5
|
+
export declare function DefaultCartPage(): import("react").JSX.Element;
|
|
6
|
+
//# sourceMappingURL=cart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cart.d.ts","sourceRoot":"","sources":["../../src/commerce/cart.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAS5D,wBAAgB,qBAAqB,CAAC,EACpC,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;CAC9B,sCAgFA;AACD,wBAAgB,eAAe,gCA4I9B"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { Link } from "@tanstack/react-router";
|
|
4
|
+
import { useStorefront, useCommerce, useCustomerQuery, customerCacheKey, emitStorefrontEvent, formatPrice, useStoreText, } from "@orunelle/theme-sdk";
|
|
5
|
+
import { useCopy, useAction, Failure, FixtureNotice, values, val, } from "./shared.js";
|
|
6
|
+
export function DefaultProductActions({ variants, }) {
|
|
7
|
+
const context = useStorefront(), session = useCommerce(), t = useCopy(), text = useStoreText(), action = useAction();
|
|
8
|
+
const available = variants.filter((v) => v.isActive && v.availableQuantity > 0);
|
|
9
|
+
const [variantId, setVariantId] = useState(available[0]?.id ?? "");
|
|
10
|
+
if (context.commerce !== "api")
|
|
11
|
+
return null;
|
|
12
|
+
const variant = available.find((v) => v.id === variantId);
|
|
13
|
+
return (_jsxs("div", { className: "product-actions", children: [_jsxs("label", { className: "form-field", children: [_jsx("span", { children: text("product.choose_option") }), _jsx("select", { "aria-label": text("product.choose_option"), value: variantId, onChange: (e) => setVariantId(e.target.value), children: available.map((v) => (_jsxs("option", { value: v.id, children: [Object.values(v.options ?? {}).join(" / ") ||
|
|
14
|
+
[v.size, v.color].filter(Boolean).join(" / ") ||
|
|
15
|
+
v.sku, v.priceOverrideMinor !== null
|
|
16
|
+
? ` — ${formatPrice({ id: v.id, handle: "", name: { en: "", ar: "" }, description: { en: "", ar: "" }, price: { amountMinor: v.priceOverrideMinor, currency: context.currency ?? "EGP" } }, context.locale)}`
|
|
17
|
+
: ""] }, v.id))) })] }), _jsxs("div", { className: "action-row", children: [_jsx("button", { disabled: !session.ready || !variant || action.pending, onClick: () => void action.run(async () => {
|
|
18
|
+
await session.client.cart.add(variantId, 1);
|
|
19
|
+
emitStorefrontEvent("product_added_to_cart", {
|
|
20
|
+
product: { id: variant?.productId },
|
|
21
|
+
variantId,
|
|
22
|
+
quantity: 1,
|
|
23
|
+
});
|
|
24
|
+
await session.cache.invalidateQueries();
|
|
25
|
+
action.setNotice(text("product.added"));
|
|
26
|
+
}), children: action.pending
|
|
27
|
+
? t("Adding…", "جارٍ الإضافة…")
|
|
28
|
+
: available.length
|
|
29
|
+
? text("product.add_to_cart")
|
|
30
|
+
: text("product.out_of_stock") }), _jsx("button", { className: "button-secondary", disabled: !session.ready ||
|
|
31
|
+
!session.authenticated ||
|
|
32
|
+
!variant ||
|
|
33
|
+
action.pending, onClick: () => void action.run(async () => {
|
|
34
|
+
await session.client.wishlist.add(variantId);
|
|
35
|
+
await session.cache.invalidateQueries();
|
|
36
|
+
action.setNotice(t("Saved to your wishlist.", "تم الحفظ في المفضلة."));
|
|
37
|
+
}), children: text("product.wishlist") })] }), _jsx("p", { role: "status", children: action.notice }), _jsx(Failure, { error: action.error })] }));
|
|
38
|
+
}
|
|
39
|
+
export function DefaultCartPage() {
|
|
40
|
+
const context = useStorefront(), session = useCommerce(), t = useCopy(), text = useStoreText(), action = useAction();
|
|
41
|
+
const query = useCustomerQuery(customerCacheKey(context, "cart"), session.client.cart.read, context.commerce === "api");
|
|
42
|
+
useEffect(() => emitStorefrontEvent("cart_viewed"), []);
|
|
43
|
+
return (_jsxs("section", { className: "account-page", children: [_jsx("h1", { children: text("cart.title") }), context.commerce !== "api" ? (_jsx(FixtureNotice, {})) : (_jsxs(_Fragment, { children: [_jsx(Failure, { error: query.error || action.error }), query.isPending ? (_jsx("p", { role: "status", children: t("Loading cart…", "جارٍ تحميل السلة…") })) : (query.data && (_jsxs(_Fragment, { children: [query.data.items.length ? (_jsx("ul", { className: "resource-list", children: query.data.items.map((line) => (_jsxs("li", { children: [_jsx(Link, { to: `/${context.locale}/products/${line.productHandle}`, children: line.name }), _jsx("p", { children: formatPrice({
|
|
44
|
+
id: line.id,
|
|
45
|
+
handle: "",
|
|
46
|
+
name: { en: "", ar: "" },
|
|
47
|
+
description: { en: "", ar: "" },
|
|
48
|
+
price: {
|
|
49
|
+
amountMinor: line.unitPriceMinor,
|
|
50
|
+
currency: query.data.currency,
|
|
51
|
+
},
|
|
52
|
+
}, context.locale) }), _jsxs("form", { className: "quantity-field", method: "post", onSubmit: (event) => {
|
|
53
|
+
const data = values(event);
|
|
54
|
+
const quantity = Number(val(data, "quantity"));
|
|
55
|
+
if (Number.isSafeInteger(quantity) &&
|
|
56
|
+
quantity > 0 &&
|
|
57
|
+
quantity !== line.quantity)
|
|
58
|
+
void action.run(async () => {
|
|
59
|
+
await session.client.cart.update(line.id, quantity);
|
|
60
|
+
await query.refetch();
|
|
61
|
+
});
|
|
62
|
+
}, children: [_jsxs("label", { children: [t("Quantity", "الكمية"), _jsx("input", { name: "quantity", type: "number", required: true, min: "1", max: Math.max(line.availableQuantity, line.quantity), defaultValue: line.quantity, disabled: action.pending })] }), _jsx("button", { className: "button-secondary", disabled: action.pending, children: t("Update quantity", "تحديث الكمية") })] }), line.unavailable && (_jsx("p", { children: t("This item is unavailable. Remove it to continue.", "هذا المنتج غير متاح. احذفه للمتابعة.") })), _jsx("button", { className: "button-secondary", disabled: action.pending, onClick: () => void action.run(async () => {
|
|
63
|
+
await session.client.cart.remove(line.id);
|
|
64
|
+
await query.refetch();
|
|
65
|
+
}), children: t("Remove", "حذف") })] }, line.id))) })) : (_jsx("p", { className: "empty-state", children: text("cart.empty") })), _jsxs("div", { className: "action-row", children: [_jsx(Link, { to: `/${context.locale}/products`, children: text("cart.continue") }), query.data.items.length > 0 && (_jsx(Link, { to: `/${context.locale}/checkout`, children: text("cart.checkout") })), _jsx("button", { className: "button-secondary", onClick: () => void query.refetch(), children: t("Refresh cart", "تحديث السلة") })] })] })))] }))] }));
|
|
66
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Reserved platform checkout: excluded from the author presentation registry. */
|
|
2
|
+
export declare function DefaultCheckoutPage(): import("react").JSX.Element;
|
|
3
|
+
export declare function DefaultPaymentCallback(): import("react").JSX.Element;
|
|
4
|
+
//# sourceMappingURL=checkout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../src/commerce/checkout.tsx"],"names":[],"mappings":"AA+YA,kFAAkF;AAClF,wBAAgB,mBAAmB,gCAUlC;AACD,wBAAgB,sBAAsB,gCAsBrC"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect } from "react";
|
|
3
|
+
import { useLocation } from "@tanstack/react-router";
|
|
4
|
+
import { Link } from "@tanstack/react-router";
|
|
5
|
+
import { useStorefront, useCommerce, useCustomerQuery, customerCacheKey, formatMoney, } from "@orunelle/theme-sdk";
|
|
6
|
+
import { CommerceError, } from "@orunelle/theme-sdk/commerce";
|
|
7
|
+
import { Orders, OrderDetails } from "./orders.js";
|
|
8
|
+
import { useCopy, useAction, Failure, Guard } from "./shared.js";
|
|
9
|
+
function Checkout() {
|
|
10
|
+
const context = useStorefront(), session = useCommerce(), t = useCopy(), action = useAction();
|
|
11
|
+
const addresses = useCustomerQuery(customerCacheKey(context, "addresses"), session.client.addresses.list, session.authenticated);
|
|
12
|
+
const methods = useCustomerQuery(customerCacheKey(context, "payment-methods"), session.client.payments.methods, session.authenticated);
|
|
13
|
+
const [addressId, setAddressId] = useState(""), [shippingOptionId, setShippingOptionId] = useState(""), [paymentMethod, setPaymentMethod] = useState(""), [order, setOrder] = useState(), [recovery, setRecovery] = useState();
|
|
14
|
+
const summary = useCustomerQuery([
|
|
15
|
+
...customerCacheKey(context, "summary"),
|
|
16
|
+
addressId,
|
|
17
|
+
shippingOptionId,
|
|
18
|
+
paymentMethod,
|
|
19
|
+
], () => session.client.cart.summary({
|
|
20
|
+
addressId,
|
|
21
|
+
...(shippingOptionId ? { shippingOptionId } : {}),
|
|
22
|
+
...(paymentMethod ? { paymentMethod } : {}),
|
|
23
|
+
}), session.authenticated && !!addressId);
|
|
24
|
+
const pendingKey = `orunelle.checkout.v2:${context.store.id}:${session.customerId}`;
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (!session.customerId)
|
|
27
|
+
return;
|
|
28
|
+
try {
|
|
29
|
+
const raw = sessionStorage.getItem(pendingKey);
|
|
30
|
+
if (raw) {
|
|
31
|
+
const saved = JSON.parse(raw);
|
|
32
|
+
if (saved &&
|
|
33
|
+
typeof saved === "object" &&
|
|
34
|
+
"scope" in saved &&
|
|
35
|
+
"body" in saved &&
|
|
36
|
+
"requestKey" in saved &&
|
|
37
|
+
typeof saved.body === "string" &&
|
|
38
|
+
typeof saved.requestKey === "string")
|
|
39
|
+
setRecovery(saved);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
/* Storage may be unavailable; in-memory recovery remains available. */
|
|
44
|
+
}
|
|
45
|
+
}, [pendingKey, session.customerId]);
|
|
46
|
+
function remember(value) {
|
|
47
|
+
try {
|
|
48
|
+
if (value)
|
|
49
|
+
sessionStorage.setItem(pendingKey, JSON.stringify(value));
|
|
50
|
+
else
|
|
51
|
+
sessionStorage.removeItem(pendingKey);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
/* Do not block a confirmed order on browser storage. */
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async function pay(placed) {
|
|
58
|
+
if (placed.paymentMethod === "paymob" || placed.paymentMethod === "xpay") {
|
|
59
|
+
const result = await session.client.payments.start(placed.paymentMethod, placed.orderNumber);
|
|
60
|
+
if (result.paymentUrl) {
|
|
61
|
+
const url = new URL(result.paymentUrl);
|
|
62
|
+
if (url.protocol !== "https:" || url.username || url.password)
|
|
63
|
+
throw new Error("Invalid payment URL");
|
|
64
|
+
window.location.assign(url.href);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (order)
|
|
69
|
+
return (_jsxs(_Fragment, { children: [_jsx(OrderDetails, { order: order }), order.paymentMethod !== "cod" && order.paymentStatus !== "paid" && (_jsx("button", { disabled: action.pending, onClick: () => void action.run(() => pay(order)), children: t("Continue to payment", "متابعة الدفع") })), _jsx(Failure, { error: action.error })] }));
|
|
70
|
+
return (_jsxs(_Fragment, { children: [_jsx(Failure, { error: addresses.error || methods.error || summary.error || action.error }), _jsxs("form", { className: "store-form", method: "post", onSubmit: (e) => {
|
|
71
|
+
e.preventDefault();
|
|
72
|
+
if (!summary.data || !shippingOptionId || recovery)
|
|
73
|
+
return;
|
|
74
|
+
const input = {
|
|
75
|
+
addressId,
|
|
76
|
+
shippingOptionId,
|
|
77
|
+
paymentMethod,
|
|
78
|
+
expectedTotalMinor: summary.data.totals.totalMinor,
|
|
79
|
+
};
|
|
80
|
+
const key = crypto.randomUUID();
|
|
81
|
+
const prepared = session.client.prepareCheckout(input, key);
|
|
82
|
+
remember(prepared);
|
|
83
|
+
void action.run(async () => {
|
|
84
|
+
try {
|
|
85
|
+
const result = await session.client.checkout(input, key);
|
|
86
|
+
remember();
|
|
87
|
+
setOrder(result.order);
|
|
88
|
+
await session.cache.invalidateQueries();
|
|
89
|
+
await pay(result.order);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
if (error instanceof CommerceError && error.recovery) {
|
|
93
|
+
setRecovery(error.recovery);
|
|
94
|
+
remember(error.recovery);
|
|
95
|
+
}
|
|
96
|
+
else
|
|
97
|
+
remember();
|
|
98
|
+
if (error instanceof CommerceError &&
|
|
99
|
+
error.code === "CART_PRICE_CHANGED")
|
|
100
|
+
await summary.refetch();
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}, children: [addresses.isPending && (_jsx("p", { role: "status", children: t("Loading delivery addresses…", "جارٍ تحميل عناوين التوصيل…") })), addresses.data?.length === 0 && (_jsx("p", { role: "status", children: t("Add a delivery address before placing your order.", "أضف عنوان توصيل قبل تأكيد الطلب.") })), _jsxs("label", { className: "form-field", children: [_jsx("span", { children: t("Delivery address", "عنوان التوصيل") }), _jsxs("select", { "aria-label": t("Delivery address", "عنوان التوصيل"), required: true, value: addressId, disabled: !!recovery, onChange: (e) => {
|
|
105
|
+
setAddressId(e.target.value);
|
|
106
|
+
setShippingOptionId("");
|
|
107
|
+
}, children: [_jsx("option", { value: "", children: t("Choose an address", "اختر عنوانًا") }), addresses.data?.map((a) => (_jsxs("option", { value: a.id, children: [a.label, " \u00B7 ", a.city] }, a.id)))] })] }), _jsx(Link, { to: `/${context.locale}/account/addresses`, children: t("Add or edit addresses", "إضافة أو تعديل العناوين") }), _jsxs("label", { className: "form-field", children: [_jsx("span", { children: t("Payment method", "طريقة الدفع") }), _jsxs("select", { "aria-label": t("Payment method", "طريقة الدفع"), required: true, value: paymentMethod, disabled: !!recovery, onChange: (e) => setPaymentMethod(e.target.value), children: [_jsx("option", { value: "", children: t("Choose a payment method", "اختر طريقة الدفع") }), methods.data?.map((method) => (_jsx("option", { value: method.method, children: method.method === "cod"
|
|
108
|
+
? t("Cash on delivery", "الدفع عند الاستلام")
|
|
109
|
+
: method.name }, method.method)))] })] }), methods.isPending && (_jsx("p", { role: "status", children: t("Loading payment methods…", "جارٍ تحميل طرق الدفع…") })), methods.data?.length === 0 && (_jsx("p", { role: "status", children: t("No payment methods are currently available. Please try again later.", "لا توجد طرق دفع متاحة حاليًا. يرجى المحاولة لاحقًا.") })), !addressId && (_jsx("p", { role: "status", children: t("Choose an address to calculate delivery and your order total.", "اختر عنوانًا لحساب التوصيل وإجمالي الطلب.") })), addressId && summary.isFetching && (_jsx("p", { role: "status", children: t("Updating your order summary…", "جارٍ تحديث ملخص الطلب…") })), summary.data && (_jsxs(_Fragment, { children: [_jsxs("label", { className: "form-field", children: [_jsx("span", { children: t("Delivery option", "خيار التوصيل") }), _jsxs("select", { "aria-label": t("Delivery option", "خيار التوصيل"), required: true, disabled: !!recovery, value: shippingOptionId, onChange: (e) => setShippingOptionId(e.target.value), children: [_jsx("option", { value: "", children: t("Choose delivery", "اختر التوصيل") }), summary.data.shippingOptions.map((option) => (_jsxs("option", { value: option.id, children: [option.name, " \u00B7", " ", formatMoney(option.amountMinor, summary.data.totals.currency, context.locale)] }, option.id)))] })] }), summary.data.shippingOptions.length === 0 && (_jsx("p", { role: "status", children: t("No delivery options are available for this address and cart. Choose another address or edit your cart.", "لا تتوفر خيارات توصيل لهذا العنوان والسلة. اختر عنوانًا آخر أو عدّل السلة.") })), _jsxs("section", { className: "checkout-review", "aria-label": t("Order summary", "ملخص الطلب"), children: [_jsx("h2", { children: t("Review your order", "راجع طلبك") }), _jsx("ul", { className: "resource-list", children: summary.data.cart.items.map((line) => (_jsxs("li", { children: [_jsx("strong", { children: line.name }), _jsxs("p", { children: [t("Item code", "رمز الصنف"), ": ", line.sku] }), _jsxs("p", { children: [t("Quantity", "الكمية"), ": ", line.quantity] }), _jsx("p", { children: formatMoney(line.unitPriceMinor * line.quantity, summary.data.cart.currency, context.locale) })] }, line.id))) }), summary.data.cart.items.length === 0 && (_jsx("p", { role: "status", children: t("Your cart is empty. Add products before placing an order.", "السلة فارغة. أضف منتجات قبل تأكيد الطلب.") })), _jsx(Link, { to: `/${context.locale}/cart`, children: t("Edit cart", "تعديل السلة") }), _jsx("dl", { className: "totals-list", children: [
|
|
110
|
+
[
|
|
111
|
+
t("Subtotal", "المجموع الفرعي"),
|
|
112
|
+
summary.data.totals.subtotalMinor,
|
|
113
|
+
],
|
|
114
|
+
[
|
|
115
|
+
t("Discount", "الخصم"),
|
|
116
|
+
-summary.data.totals.discountMinor,
|
|
117
|
+
],
|
|
118
|
+
[t("Shipping", "الشحن"), summary.data.totals.shippingMinor],
|
|
119
|
+
[
|
|
120
|
+
summary.data.totals.taxInclusive
|
|
121
|
+
? t("Tax included", "الضريبة المشمولة")
|
|
122
|
+
: t("Tax", "الضريبة"),
|
|
123
|
+
summary.data.totals.taxMinor,
|
|
124
|
+
],
|
|
125
|
+
[t("Total", "الإجمالي"), summary.data.totals.totalMinor],
|
|
126
|
+
].map(([label, amount], index) => (_jsxs("div", { className: index === 4 ? "checkout-total" : undefined, children: [_jsx("dt", { children: label }), _jsx("dd", { children: formatMoney(amount, summary.data.totals.currency, context.locale) })] }, label))) })] })] })), _jsx("button", { type: "button", className: "button-secondary", disabled: !addressId || summary.isFetching || action.pending || !!recovery, onClick: () => void summary.refetch(), children: t("Refresh order summary", "تحديث ملخص الطلب") }), _jsx("button", { disabled: action.pending ||
|
|
127
|
+
!!recovery ||
|
|
128
|
+
!summary.data ||
|
|
129
|
+
summary.data.cart.items.length === 0 ||
|
|
130
|
+
summary.isFetching ||
|
|
131
|
+
!paymentMethod ||
|
|
132
|
+
!shippingOptionId ||
|
|
133
|
+
summary.data.selectedShipping?.id !== shippingOptionId, children: action.pending
|
|
134
|
+
? t("Placing order…", "جارٍ تأكيد الطلب…")
|
|
135
|
+
: t("Place order", "تأكيد الطلب") })] }), recovery && (_jsxs("div", { className: "empty-state", children: [_jsx("p", { children: t("The order result is uncertain. Recover this order before submitting another.", "نتيجة الطلب غير مؤكدة. استعد هذا الطلب قبل إرسال طلب آخر.") }), _jsx("button", { disabled: action.pending, onClick: () => void action.run(async () => {
|
|
136
|
+
const result = await session.client.recoverCheckout(recovery);
|
|
137
|
+
remember();
|
|
138
|
+
setRecovery(undefined);
|
|
139
|
+
setOrder(result.order);
|
|
140
|
+
await pay(result.order);
|
|
141
|
+
}), children: t("Recover order", "استعادة الطلب") })] }))] }));
|
|
142
|
+
}
|
|
143
|
+
/** Reserved platform checkout: excluded from the author presentation registry. */
|
|
144
|
+
export function DefaultCheckoutPage() {
|
|
145
|
+
const t = useCopy();
|
|
146
|
+
return (_jsxs("section", { className: "account-page", children: [_jsx("h1", { children: t("Checkout", "إتمام الطلب") }), _jsx(Guard, { children: _jsx(Checkout, {}) })] }));
|
|
147
|
+
}
|
|
148
|
+
export function DefaultPaymentCallback() {
|
|
149
|
+
const { searchStr } = useLocation(), t = useCopy();
|
|
150
|
+
const number = new URLSearchParams(searchStr).get("order");
|
|
151
|
+
return (_jsxs("section", { className: "account-page", children: [_jsx("h1", { children: t("Payment result", "نتيجة الدفع") }), _jsx("p", { children: t("Payment status below comes from your order. A provider redirect does not confirm payment.", "حالة الدفع أدناه من طلبك. إعادة توجيه مزود الدفع لا تؤكد نجاح الدفع.") }), _jsx(Guard, { children: number ? (_jsx(Orders, { number: number })) : (_jsx("p", { children: t("No order number was supplied.", "لم يتم توفير رقم الطلب.") })) })] }));
|
|
152
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Order } from "@orunelle/theme-sdk/commerce";
|
|
2
|
+
export declare function OrderDetails({ order }: {
|
|
3
|
+
order: Order;
|
|
4
|
+
}): import("react").JSX.Element;
|
|
5
|
+
export declare function Orders({ number }: {
|
|
6
|
+
number?: string;
|
|
7
|
+
}): import("react").JSX.Element;
|
|
8
|
+
//# sourceMappingURL=orders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orders.d.ts","sourceRoot":"","sources":["../../src/commerce/orders.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAE1D,wBAAgB,YAAY,CAAC,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,+BA6BvD;AACD,wBAAgB,MAAM,CAAC,EAAE,MAAW,EAAE,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,+BA4D1D"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Link } from "@tanstack/react-router";
|
|
4
|
+
import { useStorefront, useCommerce, useCustomerQuery, customerCacheKey, formatMoney, } from "@orunelle/theme-sdk";
|
|
5
|
+
import { useCopy, Failure } from "./shared.js";
|
|
6
|
+
export function OrderDetails({ order }) {
|
|
7
|
+
const t = useCopy();
|
|
8
|
+
const { locale } = useStorefront();
|
|
9
|
+
return (_jsxs("article", { className: "order-details", children: [_jsxs("h2", { children: [t("Order", "الطلب"), " ", order.orderNumber] }), _jsxs("dl", { children: [_jsx("dt", { children: t("Order status", "حالة الطلب") }), _jsx("dd", { children: order.status }), _jsx("dt", { children: t("Payment status", "حالة الدفع") }), _jsx("dd", { children: order.paymentStatus }), _jsx("dt", { children: t("Delivery", "التوصيل") }), _jsx("dd", { children: order.delivery.name }), _jsx("dt", { children: t("Total", "الإجمالي") }), _jsx("dd", { children: formatMoney(order.totals.totalMinor, order.totals.currency, locale) })] }), _jsx("ul", { className: "resource-list", children: order.items.map((item) => (_jsxs("li", { children: [item.name, " \u00D7 ", item.quantity] }, item.id))) })] }));
|
|
10
|
+
}
|
|
11
|
+
export function Orders({ number = "" }) {
|
|
12
|
+
const context = useStorefront(), session = useCommerce(), t = useCopy();
|
|
13
|
+
const [page, setPage] = useState(1);
|
|
14
|
+
const query = useCustomerQuery([...customerCacheKey(context, "orders"), page], () => session.client.orders.list(page), session.authenticated && !number);
|
|
15
|
+
const detail = useCustomerQuery([...customerCacheKey(context, "order"), number], () => session.client.orders.get(number), session.authenticated && !!number);
|
|
16
|
+
if (number)
|
|
17
|
+
return (_jsxs(_Fragment, { children: [_jsx(Failure, { error: detail.error }), detail.data ? (_jsx(OrderDetails, { order: detail.data })) : (_jsx("p", { role: "status", children: t("Loading order…", "جارٍ تحميل الطلب…") }))] }));
|
|
18
|
+
return (_jsxs(_Fragment, { children: [_jsx(Failure, { error: query.error }), _jsx("ul", { className: "resource-list", children: query.data?.items.map((order) => (_jsxs("li", { children: [_jsx(Link, { to: `/${context.locale}/account/orders/${order.orderNumber}`, children: order.orderNumber }), _jsxs("p", { children: [order.status, " \u00B7 ", order.paymentStatus] })] }, order.id))) }), query.data?.items.length === 0 && (_jsx("p", { className: "empty-state", children: t("You have no orders yet.", "ليس لديك طلبات بعد.") })), _jsxs("div", { className: "action-row", children: [page > 1 && (_jsx("button", { onClick: () => setPage((p) => p - 1), children: t("Previous", "السابق") })), query.data && page < query.data.pagination.pages && (_jsx("button", { onClick: () => setPage((p) => p + 1), children: t("Next", "التالي") }))] })] }));
|
|
19
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type RoutePageData } from "@orunelle/theme-sdk";
|
|
2
|
+
export declare function DefaultCatalogPage({ data, }: {
|
|
3
|
+
data: Extract<RoutePageData, {
|
|
4
|
+
kind: "catalog";
|
|
5
|
+
}>;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
7
|
+
export declare function DefaultCollectionsPage({ data, }: {
|
|
8
|
+
data: Extract<RoutePageData, {
|
|
9
|
+
kind: "collections";
|
|
10
|
+
}>;
|
|
11
|
+
}): import("react").JSX.Element;
|
|
12
|
+
export declare function DefaultContentPage({ data, }: {
|
|
13
|
+
data: Extract<RoutePageData, {
|
|
14
|
+
kind: "content";
|
|
15
|
+
}>;
|
|
16
|
+
}): import("react").JSX.Element;
|
|
17
|
+
//# sourceMappingURL=public-pages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-pages.d.ts","sourceRoot":"","sources":["../../src/commerce/public-pages.tsx"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,aAAa,EACnB,MAAM,qBAAqB,CAAC;AAE7B,wBAAgB,kBAAkB,CAAC,EACjC,IAAI,GACL,EAAE;IACD,IAAI,EAAE,OAAO,CAAC,aAAa,EAAE;QAAE,IAAI,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;CACnD,+BAqCA;AACD,wBAAgB,sBAAsB,CAAC,EACrC,IAAI,GACL,EAAE;IACD,IAAI,EAAE,OAAO,CAAC,aAAa,EAAE;QAAE,IAAI,EAAE,aAAa,CAAA;KAAE,CAAC,CAAC;CACvD,+BA2BA;AACD,wBAAgB,kBAAkB,CAAC,EACjC,IAAI,GACL,EAAE;IACD,IAAI,EAAE,OAAO,CAAC,aAAa,EAAE;QAAE,IAAI,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;CACnD,+BASA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Link, useLocation } from "@tanstack/react-router";
|
|
3
|
+
import { useStorefront, useThemeComponents, } from "@orunelle/theme-sdk";
|
|
4
|
+
import { useCopy, Field, Pagination } from "./shared.js";
|
|
5
|
+
export function DefaultCatalogPage({ data, }) {
|
|
6
|
+
const { ProductCard } = useThemeComponents();
|
|
7
|
+
const t = useCopy();
|
|
8
|
+
const { locale } = useStorefront();
|
|
9
|
+
const { searchStr } = useLocation();
|
|
10
|
+
return (_jsxs("section", { className: "catalog-section", children: [_jsx("h1", { children: data.title }), _jsxs("form", { className: "search-form", method: "get", action: `/${locale}/search`, children: [_jsx(Field, { name: "q", label: t("Search products", "ابحث عن المنتجات"), required: false, value: new URLSearchParams(searchStr).get("q") ?? "" }), _jsx("button", { type: "submit", children: t("Search", "بحث") })] }), data.products.length ? (_jsx("div", { className: "product-grid", children: data.products.map((product) => (_jsx(ProductCard, { product: product }, product.id))) })) : (_jsxs("p", { className: "empty-state", role: "status", children: [t("No products match. Try another search or browse all products.", "لا توجد منتجات مطابقة. جرّب بحثًا آخر أو تصفح جميع المنتجات."), " ", _jsx(Link, { to: `/${locale}/products`, children: t("All products", "جميع المنتجات") })] })), _jsx(Pagination, { ...data.pagination })] }));
|
|
11
|
+
}
|
|
12
|
+
export function DefaultCollectionsPage({ data, }) {
|
|
13
|
+
const { locale } = useStorefront();
|
|
14
|
+
const t = useCopy();
|
|
15
|
+
return (_jsxs("section", { className: "catalog-section", children: [_jsx("h1", { children: data.title }), data.collections.length ? (_jsx("ul", { className: "resource-list", children: data.collections.map((item) => (_jsxs("li", { children: [_jsx(Link, { to: `/${locale}/${data.basePath ?? "collections"}/${encodeURIComponent(item.slug)}`, children: item.name }), _jsx("p", { children: item.description })] }, item.id))) })) : (_jsx("p", { className: "empty-state", children: t("There are no collections to display.", "لا توجد مجموعات للعرض.") })), _jsx(Pagination, { ...data.pagination })] }));
|
|
16
|
+
}
|
|
17
|
+
export function DefaultContentPage({ data, }) {
|
|
18
|
+
return (_jsxs("article", { className: "content-page", children: [_jsx("h1", { children: data.title }), data.paragraphs.map((paragraph, index) => (_jsx("p", { children: paragraph }, index)))] }));
|
|
19
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type FormEvent, type ReactNode } from "react";
|
|
2
|
+
export declare function useCopy(): (en: string, ar: string) => string;
|
|
3
|
+
export declare function useAction(): {
|
|
4
|
+
pending: boolean;
|
|
5
|
+
error: unknown;
|
|
6
|
+
notice: string;
|
|
7
|
+
setNotice: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
8
|
+
run(action: () => Promise<void>): Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
export declare function Failure({ error }: {
|
|
11
|
+
error: unknown;
|
|
12
|
+
}): import("react").JSX.Element | null;
|
|
13
|
+
export declare function Field({ label, name, type, required, value, autoComplete, }: {
|
|
14
|
+
label: string;
|
|
15
|
+
name: string;
|
|
16
|
+
type?: string;
|
|
17
|
+
required?: boolean;
|
|
18
|
+
value?: string;
|
|
19
|
+
autoComplete?: string;
|
|
20
|
+
}): import("react").JSX.Element;
|
|
21
|
+
export declare function values(event: FormEvent<HTMLFormElement>): FormData;
|
|
22
|
+
export declare const val: (data: FormData, name: string) => string;
|
|
23
|
+
export declare function FixtureNotice(): import("react").JSX.Element;
|
|
24
|
+
export declare function Guard({ children }: {
|
|
25
|
+
children: ReactNode;
|
|
26
|
+
}): string | number | bigint | boolean | import("react").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null | undefined;
|
|
27
|
+
export declare function Pagination({ page, pages }: {
|
|
28
|
+
page: number;
|
|
29
|
+
pages: number;
|
|
30
|
+
}): import("react").JSX.Element | null;
|
|
31
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/commerce/shared.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAIjE,wBAAgB,OAAO,KAEb,IAAI,MAAM,EAAE,IAAI,MAAM,YAC/B;AACD,wBAAgB,SAAS;;;;;gBASH,MAAM,OAAO,CAAC,IAAI,CAAC;EAcxC;AACD,wBAAgB,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,sCAsBpD;AACD,wBAAgB,KAAK,CAAC,EACpB,KAAK,EACL,IAAI,EACJ,IAAa,EACb,QAAe,EACf,KAAK,EACL,YAAY,GACb,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,+BAoBA;AACD,wBAAgB,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,eAAe,CAAC,YAGvD;AACD,eAAO,MAAM,GAAG,GAAI,MAAM,QAAQ,EAAE,MAAM,MAAM,WAClB,CAAC;AAC/B,wBAAgB,aAAa,gCAU5B;AACD,wBAAgB,KAAK,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,+TAoB1D;AACD,wBAAgB,UAAU,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,sCAkB1E"}
|