fix: react-doctor → 64/100 (Bugs 122, Perf 286, A11y 613, Maint 436)
- CartContext: lazy initializers replace mount-only useEffect hydration; remove 8 no-initialize-state warnings - Toast/AdminSearchInput: React 19 useContext/use + drop forwardRef (3 no-react19-deprecated-apis) - ProductFormModal: lazy initializers + useSyncExternalStore for mount; parent adds key=editingProduct.id - InstallPrompt: useReducer for prompt state (no-cascading-set-state) - QRScanModal: ref-based latest-callback pattern replaces useEffectEvent deps mistake - OnboardingFlow: functional setState (rerender-functional-setstate) - UsersPage/StopsCalendar/FeaturesAndStats: lazy initializers (rerender-lazy-state-init) - FAQClientPage: server-side brand settings fetch via getBrandSettingsPublic in layout; remove supabase import - LandingPageWrapper: href='#' → href='#top' (anchor-is-valid) - TuxedoVideoHero: replace animate-bounce with ease-out-expo (no-inline-bounce-easing) - ProductTableClient: useCallback for handleDeleted (jsx-no-new-function-as-prop) - excel-parser: pre-compile delimiter regexes (js-hoist-regexp) - water-log/settings: Promise.all for parallel DB calls (async-parallel) - ToastNotification: extract toast store to separate file (only-export-components) - WholesaleClient: inline <WholesaleIcon/> instead of hoisting to const (rendering-hoist-jsx)
This commit is contained in:
@@ -42,35 +42,39 @@ await getSession(); const adminUser = await getAdminUser();
|
||||
const conds: SQL[] = [eq(customers.brandId, params.brandId)];
|
||||
const recipientRows = await withBrand(params.brandId, async (db) => {
|
||||
// Distinct customers from the tenant's recent orders.
|
||||
const orderCustomers = await db
|
||||
.selectDistinct({ id: customers.id })
|
||||
.from(customers)
|
||||
.innerJoin(orders, eq(orders.customerId, customers.id))
|
||||
.where(
|
||||
and(
|
||||
eq(orders.brandId, params.brandId),
|
||||
params.channel === "sms"
|
||||
? eq(customers.smsOptIn, true)
|
||||
: params.channel === "email"
|
||||
? eq(customers.emailOptIn, true)
|
||||
: sql`(${customers.smsOptIn} = true OR ${customers.emailOptIn} = true)`,
|
||||
// These two queries are independent (no shared state between
|
||||
// them and they don't feed into each other), so run them in
|
||||
// parallel — saves a full round-trip per request.
|
||||
const [orderCustomers, countRows] = await Promise.all([
|
||||
db
|
||||
.selectDistinct({ id: customers.id })
|
||||
.from(customers)
|
||||
.innerJoin(orders, eq(orders.customerId, customers.id))
|
||||
.where(
|
||||
and(
|
||||
eq(orders.brandId, params.brandId),
|
||||
params.channel === "sms"
|
||||
? eq(customers.smsOptIn, true)
|
||||
: params.channel === "email"
|
||||
? eq(customers.emailOptIn, true)
|
||||
: sql`(${customers.smsOptIn} = true OR ${customers.emailOptIn} = true)`,
|
||||
),
|
||||
)
|
||||
.limit(1000),
|
||||
db
|
||||
.select({ value: sql<number>`count(*)::int` })
|
||||
.from(customers)
|
||||
.where(
|
||||
and(
|
||||
...conds,
|
||||
params.channel === "sms"
|
||||
? eq(customers.smsOptIn, true)
|
||||
: params.channel === "email"
|
||||
? eq(customers.emailOptIn, true)
|
||||
: sql`(${customers.smsOptIn} = true OR ${customers.emailOptIn} = true)`,
|
||||
),
|
||||
),
|
||||
)
|
||||
.limit(1000);
|
||||
|
||||
const countRows = await db
|
||||
.select({ value: sql<number>`count(*)::int` })
|
||||
.from(customers)
|
||||
.where(
|
||||
and(
|
||||
...conds,
|
||||
params.channel === "sms"
|
||||
? eq(customers.smsOptIn, true)
|
||||
: params.channel === "email"
|
||||
? eq(customers.emailOptIn, true)
|
||||
: sql`(${customers.smsOptIn} = true OR ${customers.emailOptIn} = true)`,
|
||||
),
|
||||
);
|
||||
]);
|
||||
|
||||
return {
|
||||
ids: orderCustomers.map((r) => r.id),
|
||||
|
||||
@@ -60,37 +60,39 @@ await getSession(); const adminUser = await getAdminUser();
|
||||
|
||||
try {
|
||||
const [orderRows, campaignRows] = await withBrand(brandId, async (db) => {
|
||||
const o = await db
|
||||
.select({
|
||||
id: orders.id,
|
||||
status: orders.status,
|
||||
placedAt: orders.placedAt,
|
||||
customerName: customers.fullName,
|
||||
customerEmail: customers.email,
|
||||
customerPhone: customers.phone,
|
||||
})
|
||||
.from(orders)
|
||||
.innerJoin(customers, eq(customers.id, orders.customerId))
|
||||
.where(
|
||||
and(
|
||||
eq(orders.brandId, brandId),
|
||||
isNotNull(customers.email),
|
||||
),
|
||||
)
|
||||
.orderBy(desc(orders.placedAt))
|
||||
.limit(50);
|
||||
|
||||
const c = await db
|
||||
.select({
|
||||
id: campaigns.id,
|
||||
name: campaigns.name,
|
||||
sentAt: campaigns.sentAt,
|
||||
updatedAt: campaigns.updatedAt,
|
||||
})
|
||||
.from(campaigns)
|
||||
.where(eq(campaigns.brandId, brandId))
|
||||
.orderBy(desc(campaigns.sentAt), desc(campaigns.updatedAt))
|
||||
.limit(10);
|
||||
// Independent reads — fire in parallel.
|
||||
const [o, c] = await Promise.all([
|
||||
db
|
||||
.select({
|
||||
id: orders.id,
|
||||
status: orders.status,
|
||||
placedAt: orders.placedAt,
|
||||
customerName: customers.fullName,
|
||||
customerEmail: customers.email,
|
||||
customerPhone: customers.phone,
|
||||
})
|
||||
.from(orders)
|
||||
.innerJoin(customers, eq(customers.id, orders.customerId))
|
||||
.where(
|
||||
and(
|
||||
eq(orders.brandId, brandId),
|
||||
isNotNull(customers.email),
|
||||
),
|
||||
)
|
||||
.orderBy(desc(orders.placedAt))
|
||||
.limit(50),
|
||||
db
|
||||
.select({
|
||||
id: campaigns.id,
|
||||
name: campaigns.name,
|
||||
sentAt: campaigns.sentAt,
|
||||
updatedAt: campaigns.updatedAt,
|
||||
})
|
||||
.from(campaigns)
|
||||
.where(eq(campaigns.brandId, brandId))
|
||||
.orderBy(desc(campaigns.sentAt), desc(campaigns.updatedAt))
|
||||
.limit(10),
|
||||
]);
|
||||
|
||||
return [o, c] as const;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user