fix: react-doctor label-has-associated-control 9→0, async-await-in-loop 3→0 (Promise.allSettled), role-supports-aria-props 3→0 (already done in prior batch)
This commit is contained in:
@@ -340,15 +340,13 @@ await getSession(); const adminUser = await getAdminUser();
|
|||||||
return { success: false, error: "Not authorized for this brand" };
|
return { success: false, error: "Not authorized for this brand" };
|
||||||
}
|
}
|
||||||
|
|
||||||
const result: ImportResult = { created: 0, updated: 0, skipped: 0, errors: [] };
|
const validRows = params.contacts.filter(
|
||||||
|
(row) => row.email || row.phone,
|
||||||
|
);
|
||||||
|
|
||||||
for (const row of params.contacts) {
|
const settled = await Promise.allSettled(
|
||||||
if (!row.email && !row.phone) {
|
validRows.map((row) =>
|
||||||
result.skipped++;
|
upsertContact({
|
||||||
continue;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const r = await upsertContact({
|
|
||||||
brand_id: params.brandId,
|
brand_id: params.brandId,
|
||||||
email: row.email,
|
email: row.email,
|
||||||
phone: row.phone,
|
phone: row.phone,
|
||||||
@@ -361,16 +359,42 @@ await getSession(); const adminUser = await getAdminUser();
|
|||||||
external_id: row.external_id,
|
external_id: row.external_id,
|
||||||
tags: row.tags,
|
tags: row.tags,
|
||||||
metadata: row._metadata,
|
metadata: row._metadata,
|
||||||
});
|
}).then(
|
||||||
if (r.success) result.created++;
|
(r) => ({ row, r }),
|
||||||
else {
|
(err) => ({ row, err }),
|
||||||
result.errors.push({ row, error: r.error });
|
),
|
||||||
}
|
),
|
||||||
} catch (err) {
|
);
|
||||||
|
|
||||||
|
const result: ImportResult = {
|
||||||
|
created: 0,
|
||||||
|
updated: 0,
|
||||||
|
skipped: params.contacts.length - validRows.length,
|
||||||
|
errors: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const entry of settled) {
|
||||||
|
if (entry.status === "rejected") {
|
||||||
|
const err = (entry as PromiseRejectedResult).reason;
|
||||||
result.errors.push({
|
result.errors.push({
|
||||||
row,
|
row: validRows[settled.indexOf(entry)],
|
||||||
error: err instanceof Error ? err.message : String(err),
|
error: err instanceof Error ? err.message : String(err),
|
||||||
});
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const value = entry.value as
|
||||||
|
| { row: ContactImportEntry; r: { success: boolean; error?: string } }
|
||||||
|
| { row: ContactImportEntry; err: unknown };
|
||||||
|
if ("err" in value) {
|
||||||
|
const err = value.err;
|
||||||
|
result.errors.push({
|
||||||
|
row: value.row,
|
||||||
|
error: err instanceof Error ? err.message : String(err),
|
||||||
|
});
|
||||||
|
} else if (value.r.success) {
|
||||||
|
result.created++;
|
||||||
|
} else {
|
||||||
|
result.errors.push({ row: value.row, error: value.r.error ?? "Unknown error" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,29 +40,56 @@ await getSession(); const adminUser = await getAdminUser();
|
|||||||
let created = 0;
|
let created = 0;
|
||||||
const errors: { product: string; error: string }[] = [];
|
const errors: { product: string; error: string }[] = [];
|
||||||
|
|
||||||
|
const validProducts: Array<{ name: string; description: string; price: number; type: string; active: boolean; image_url?: string }> = [];
|
||||||
|
const skipped: { product: { name: string; description: string; price: number; type: string; active: boolean; image_url?: string }; error: string }[] = [];
|
||||||
for (const p of productsToImport) {
|
for (const p of productsToImport) {
|
||||||
const priceCents = Math.round(Number(p.price) * 100);
|
const priceCents = Math.round(Number(p.price) * 100);
|
||||||
if (!Number.isFinite(priceCents) || priceCents < 0) {
|
if (!Number.isFinite(priceCents) || priceCents < 0) {
|
||||||
errors.push({ product: p.name, error: "Invalid price" });
|
skipped.push({ product: p, error: "Invalid price" });
|
||||||
continue;
|
} else {
|
||||||
|
validProducts.push(p);
|
||||||
}
|
}
|
||||||
try {
|
}
|
||||||
await withBrand(brandId, (db) =>
|
|
||||||
|
const settled = await Promise.allSettled(
|
||||||
|
validProducts.map((p) =>
|
||||||
|
withBrand(brandId, (db) =>
|
||||||
db.insert(products).values({
|
db.insert(products).values({
|
||||||
brandId: brandId,
|
brandId: brandId,
|
||||||
name: p.name,
|
name: p.name,
|
||||||
description: p.description ?? null,
|
description: p.description ?? null,
|
||||||
priceCents,
|
priceCents: Math.round(Number(p.price) * 100),
|
||||||
active: p.active,
|
active: p.active,
|
||||||
})
|
}),
|
||||||
|
).then(
|
||||||
|
() => p,
|
||||||
|
(err) => ({ p, err }),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
created++;
|
|
||||||
} catch (err) {
|
for (const entry of settled) {
|
||||||
|
if (entry.status === "rejected") {
|
||||||
|
const err = (entry as PromiseRejectedResult).reason;
|
||||||
errors.push({
|
errors.push({
|
||||||
product: p.name,
|
product: "<unknown>",
|
||||||
error: err instanceof Error ? err.message : String(err),
|
error: err instanceof Error ? err.message : String(err),
|
||||||
});
|
});
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
const value = entry.value;
|
||||||
|
if ("err" in value) {
|
||||||
|
errors.push({
|
||||||
|
product: value.p.name,
|
||||||
|
error: value.err instanceof Error ? value.err.message : String(value.err),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
created++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const s of skipped) {
|
||||||
|
errors.push({ product: s.product.name, error: s.error });
|
||||||
}
|
}
|
||||||
|
|
||||||
return { success: true, created, updated: 0, errors };
|
return { success: true, created, updated: 0, errors };
|
||||||
|
|||||||
@@ -101,14 +101,38 @@ await getSession(); const adminUser = await getAdminUser();
|
|||||||
since
|
since
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const payment of paymentsData.payments ?? []) {
|
interface SquarePayment {
|
||||||
try {
|
id: string;
|
||||||
// Skip if no order_id
|
order_id?: string;
|
||||||
if (!payment.order_id) continue;
|
status?: string;
|
||||||
// Skip if already completed/canceled
|
amount_money?: { amount?: string; currency?: string };
|
||||||
if (!completedStatuses.has(payment.status ?? "")) continue;
|
customer_id?: string;
|
||||||
|
receipt_number?: string;
|
||||||
|
}
|
||||||
|
|
||||||
const orderData = await fetchSquareOrder(settings.square_access_token, payment.order_id);
|
const processablePayments = ((paymentsData.payments ?? []) as SquarePayment[]).filter(
|
||||||
|
(p) => Boolean(p.order_id) && completedStatuses.has(p.status ?? ""),
|
||||||
|
);
|
||||||
|
|
||||||
|
const orderResults = await Promise.allSettled(
|
||||||
|
processablePayments.map((p) =>
|
||||||
|
fetchSquareOrder(settings.square_access_token!, p.order_id!).then(
|
||||||
|
(data) => ({ payment: p, orderData: data, err: undefined as unknown }),
|
||||||
|
(err: unknown) => ({ payment: p, orderData: undefined, err }),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const result of orderResults) {
|
||||||
|
if (result.status === "rejected") {
|
||||||
|
errors.push(`Square order fetch: ${String(result.reason)}`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const { payment, orderData, err } = result.value;
|
||||||
|
if (err || !orderData) {
|
||||||
|
errors.push(`Payment ${payment.id}: ${String(err ?? "no order data")}`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const order = orderData.order;
|
const order = orderData.order;
|
||||||
|
|
||||||
// Build line items from Square order
|
// Build line items from Square order
|
||||||
@@ -175,9 +199,6 @@ await getSession(); const adminUser = await getAdminUser();
|
|||||||
} else {
|
} else {
|
||||||
errors.push(`Payment ${payment.id}: ${errText}`);
|
errors.push(`Payment ${payment.id}: ${errText}`);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
|
||||||
errors.push(`Payment ${payment.id}: ${String(err)}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
errors.push(`Sync error: ${String(err)}`);
|
errors.push(`Sync error: ${String(err)}`);
|
||||||
|
|||||||
@@ -273,7 +273,8 @@ export default function ProductEditForm({ product, brands }: ProductEditFormProp
|
|||||||
</AdminInput>
|
</AdminInput>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label className="mb-2 block text-sm font-medium text-[var(--admin-text-primary)]" htmlFor="fld-status">Status</label><label className="mb-2 block text-sm font-medium text-[var(--admin-text-primary)]">Status</label>
|
<label className="mb-2 block text-sm font-medium text-[var(--admin-text-primary)]">
|
||||||
|
<span className="block mb-2">Status</span>
|
||||||
<button type="button"
|
<button type="button"
|
||||||
onClick={() => setActive((v) => !v)}
|
onClick={() => setActive((v) => !v)}
|
||||||
className={`w-full rounded-xl px-4 py-3 text-sm font-medium transition-colors ${
|
className={`w-full rounded-xl px-4 py-3 text-sm font-medium transition-colors ${
|
||||||
@@ -284,10 +285,12 @@ export default function ProductEditForm({ product, brands }: ProductEditFormProp
|
|||||||
>
|
>
|
||||||
{active ? "Active" : "Inactive"}
|
{active ? "Active" : "Inactive"}
|
||||||
</button>
|
</button>
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label className="mb-2 block text-sm font-medium text-[var(--admin-text-primary)]" htmlFor="fld-taxable">Taxable</label><label className="mb-2 block text-sm font-medium text-[var(--admin-text-primary)]">Taxable</label>
|
<label className="mb-2 block text-sm font-medium text-[var(--admin-text-primary)]">
|
||||||
|
<span className="block mb-2">Taxable</span>
|
||||||
<button type="button"
|
<button type="button"
|
||||||
onClick={() => setIs_taxable((v) => !v)}
|
onClick={() => setIs_taxable((v) => !v)}
|
||||||
className={`w-full rounded-xl px-4 py-3 text-sm font-medium transition-colors flex items-center gap-3 ${
|
className={`w-full rounded-xl px-4 py-3 text-sm font-medium transition-colors flex items-center gap-3 ${
|
||||||
@@ -296,9 +299,10 @@ export default function ProductEditForm({ product, brands }: ProductEditFormProp
|
|||||||
: "bg-[var(--admin-accent-soft)] text-[var(--admin-accent)] ring-1 ring-[var(--admin-accent)]"
|
: "bg-[var(--admin-accent-soft)] text-[var(--admin-accent)] ring-1 ring-[var(--admin-accent)]"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<span className="text-lg">{is_taxable ? "✓" : "✗"}</span>
|
<span className="text-lg" aria-hidden="true">{is_taxable ? "✓" : "✗"}</span>
|
||||||
<span>{is_taxable ? "Taxable — tax applied at checkout for nexus shipments" : "Non-taxable — always exempt from sales tax"}</span>
|
<span>{is_taxable ? "Taxable — tax applied at checkout for nexus shipments" : "Non-taxable — always exempt from sales tax"}</span>
|
||||||
</button>
|
</button>
|
||||||
|
</label>
|
||||||
<p className="mt-1.5 text-xs text-[var(--admin-text-muted)]">Tax is calculated at checkout for shipping orders in your brand's nexus states. Non-taxable items (e.g. cooler boxes, apparel) are always exempt.</p>
|
<p className="mt-1.5 text-xs text-[var(--admin-text-muted)]">Tax is calculated at checkout for shipping orders in your brand's nexus states. Non-taxable items (e.g. cooler boxes, apparel) are always exempt.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -317,7 +321,7 @@ export default function ProductEditForm({ product, brands }: ProductEditFormProp
|
|||||||
</AdminInput>
|
</AdminInput>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label className="mb-1 block text-sm font-medium text-[var(--admin-text-primary)]" htmlFor="fld-product-image">Product Image</label><label className="mb-1 block text-sm font-medium text-[var(--admin-text-primary)]">Product Image</label>
|
<span className="mb-1 block text-sm font-medium text-[var(--admin-text-primary)]">Product Image</span>
|
||||||
<p className="text-xs text-[var(--admin-text-muted)] mb-2">JPG, PNG, WebP · 1200px max width · max 5MB (ideally under 2MB)</p>
|
<p className="text-xs text-[var(--admin-text-muted)] mb-2">JPG, PNG, WebP · 1200px max width · max 5MB (ideally under 2MB)</p>
|
||||||
|
|
||||||
<label
|
<label
|
||||||
|
|||||||
@@ -163,6 +163,7 @@ export default function ScheduleImportModal({ brandId, onClose, onComplete }: Pr
|
|||||||
|
|
||||||
{/* Drop zone */}
|
{/* Drop zone */}
|
||||||
<label
|
<label
|
||||||
|
htmlFor="schedule-file-upload"
|
||||||
onDragOver={(e) => { e.preventDefault(); setDragOver(true); }}
|
onDragOver={(e) => { e.preventDefault(); setDragOver(true); }}
|
||||||
onDragLeave={() => setDragOver(false)}
|
onDragLeave={() => setDragOver(false)}
|
||||||
onDrop={handleDrop}
|
onDrop={handleDrop}
|
||||||
@@ -186,7 +187,8 @@ export default function ScheduleImportModal({ brandId, onClose, onComplete }: Pr
|
|||||||
</p>
|
</p>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<input aria-label="File upload"
|
<input id="schedule-file-upload"
|
||||||
|
aria-label="File upload"
|
||||||
ref={fileInputRef}
|
ref={fileInputRef}
|
||||||
type="file"
|
type="file"
|
||||||
accept=".csv,.txt,.json"
|
accept=".csv,.txt,.json"
|
||||||
|
|||||||
@@ -332,7 +332,8 @@ export default function StopEditForm({ stop, brands, onSaved }: StopEditFormProp
|
|||||||
</AdminInput>
|
</AdminInput>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label className="mb-2 block text-sm font-medium text-stone-700" htmlFor="fld-status">Status</label><label className="mb-2 block text-sm font-medium text-stone-700">Status</label>
|
<label className="mb-2 block text-sm font-medium text-stone-700">
|
||||||
|
<span className="block mb-2">Status</span>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setActive((v) => !v)}
|
onClick={() => setActive((v) => !v)}
|
||||||
@@ -342,8 +343,10 @@ export default function StopEditForm({ stop, brands, onSaved }: StopEditFormProp
|
|||||||
: "bg-stone-100 text-stone-500 border border-stone-200 hover:bg-stone-50"
|
: "bg-stone-100 text-stone-500 border border-stone-200 hover:bg-stone-50"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{active ? "✓ Active — visible on storefront" : "○ Inactive — hidden from storefront"}
|
<span aria-hidden="true">{active ? "✓ " : "○ "}</span>
|
||||||
|
{active ? "Active — visible on storefront" : "Inactive — hidden from storefront"}
|
||||||
</button>
|
</button>
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<AdminButton
|
<AdminButton
|
||||||
|
|||||||
@@ -80,11 +80,11 @@ export default function WaterLogEntryEditForm({ entry, backHref = "/admin/water-
|
|||||||
|
|
||||||
<div className="grid grid-cols-2 gap-4">
|
<div className="grid grid-cols-2 gap-4">
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-[var(--admin-text-muted)] mb-1" htmlFor="fld-headgate">Headgate</label><label className="block text-sm font-medium text-[var(--admin-text-muted)] mb-1">Headgate</label>
|
<span className="block text-sm font-medium text-[var(--admin-text-muted)] mb-1">Headgate</span>
|
||||||
<p className="rounded-lg border border-[var(--admin-border)] bg-[var(--admin-bg-subtle)] px-3 py-2 text-sm text-[var(--admin-text-secondary)]">{entry.headgate_name}</p>
|
<p className="rounded-lg border border-[var(--admin-border)] bg-[var(--admin-bg-subtle)] px-3 py-2 text-sm text-[var(--admin-text-secondary)]">{entry.headgate_name}</p>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-[var(--admin-text-muted)] mb-1" htmlFor="fld-user">User</label><label className="block text-sm font-medium text-[var(--admin-text-muted)] mb-1">User</label>
|
<span className="block text-sm font-medium text-[var(--admin-text-muted)] mb-1">User</span>
|
||||||
<p className="rounded-lg border border-[var(--admin-border)] bg-[var(--admin-bg-subtle)] px-3 py-2 text-sm text-[var(--admin-text-secondary)]">{entry.user_name}</p>
|
<p className="rounded-lg border border-[var(--admin-border)] bg-[var(--admin-bg-subtle)] px-3 py-2 text-sm text-[var(--admin-text-secondary)]">{entry.user_name}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -106,11 +106,11 @@ export default function WaterLogEntryEditForm({ entry, backHref = "/admin/water-
|
|||||||
/>
|
/>
|
||||||
</AdminInput>
|
</AdminInput>
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-[var(--admin-text-muted)] mb-1" htmlFor="fld-submitted-via">Submitted Via</label><label className="block text-sm font-medium text-[var(--admin-text-muted)] mb-1">Submitted Via</label>
|
<span className="block text-sm font-medium text-[var(--admin-text-muted)] mb-1">Submitted Via</span>
|
||||||
<p className="rounded-lg border border-[var(--admin-border)] bg-[var(--admin-bg-subtle)] px-3 py-2 text-sm text-[var(--admin-text-secondary)]">{entry.submitted_via}</p>
|
<p className="rounded-lg border border-[var(--admin-border)] bg-[var(--admin-bg-subtle)] px-3 py-2 text-sm text-[var(--admin-text-secondary)]">{entry.submitted_via}</p>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-[var(--admin-text-muted)] mb-1" htmlFor="fld-logged">Logged</label><label className="block text-sm font-medium text-[var(--admin-text-muted)] mb-1">Logged</label>
|
<span className="block text-sm font-medium text-[var(--admin-text-muted)] mb-1">Logged</span>
|
||||||
<p className="rounded-lg border border-[var(--admin-border)] bg-[var(--admin-bg-subtle)] px-3 py-2 text-sm text-[var(--admin-text-secondary)]">
|
<p className="rounded-lg border border-[var(--admin-border)] bg-[var(--admin-bg-subtle)] px-3 py-2 text-sm text-[var(--admin-text-secondary)]">
|
||||||
{new Date(entry.logged_at).toLocaleDateString("en-US", {
|
{new Date(entry.logged_at).toLocaleDateString("en-US", {
|
||||||
month: "short",
|
month: "short",
|
||||||
|
|||||||
Reference in New Issue
Block a user