Added some small enchances

This commit is contained in:
Oleksandr Prokhorenko
2026-09-24 22:41:06 +03:00
parent 9ccbac4aca
commit 7f3a56a4ca
21 changed files with 441 additions and 211 deletions
+5 -5
View File
@@ -64,20 +64,20 @@ export class CrmController {
});
}
@Get('merchants') async merchants(@Req() req: AuthRequest, @Query() query: unknown) {
const { page: requestedPage } = merchantQuerySchema.parse(query);
const { page: requestedPage, pageSize } = merchantQuerySchema.parse(query);
const where = merchantWhere(req.user, query);
return this.db.$transaction(
async (tx) => {
const total = await tx.merchant.count({ where });
const page = Math.min(requestedPage, Math.max(1, Math.ceil(total / 8)));
const page = Math.min(requestedPage, Math.max(1, Math.ceil(total / pageSize)));
const items = await tx.merchant.findMany({
where,
select: merchantSelect,
orderBy: [{ createdAt: 'desc' }, { id: 'asc' }],
take: 8,
skip: (page - 1) * 8,
take: pageSize,
skip: (page - 1) * pageSize,
});
return { items, total, page, pageSize: 8 };
return { items, total, page, pageSize };
},
{ isolationLevel: 'RepeatableRead' },
);
+26 -7
View File
@@ -142,7 +142,7 @@ test('staff creation is atomic, minimally required, role-bound and strict', asyn
test('search, combined filters, pagination and metadata apply ownership scope before counts', async () => {
const prefix = `Directory-${randomUUID()}`;
const ids = [];
for (let index = 0; index < 10; index++)
for (let index = 0; index < 31; index++)
ids.push(
await create('alex', {
name: `${prefix} ${index}`,
@@ -174,11 +174,20 @@ test('search, combined filters, pagination and metadata apply ownership scope be
const query = `search=${prefix}&country=GB&industry=SOFTWARE&status=NEW_LEAD`;
const page1 = (await request(`/merchants?${query}`, 'alex')).body;
const page2 = (await request(`/merchants?${query}&page=2`, 'alex')).body;
assert.equal(page1.total, 10);
assert.equal(page1.items.length, 8);
assert.equal(page2.items.length, 2);
assert.equal(new Set([...page1.items, ...page2.items].map((m) => m.id)).size, 10);
assert.equal((await request(`/merchants?${query}&page=10000`, 'alex')).body.page, 2);
assert.equal(page1.total, 31);
assert.equal(page1.items.length, 10);
assert.equal(page2.items.length, 10);
assert.equal(new Set([...page1.items, ...page2.items].map((m) => m.id)).size, 20);
assert.equal((await request(`/merchants?${query}&page=10000`, 'alex')).body.page, 4);
for (const pageSize of [10, 20, 30]) {
const first = (await request(`/merchants?${query}&pageSize=${pageSize}`, 'alex')).body;
const last = (await request(`/merchants?${query}&pageSize=${pageSize}&page=10000`, 'alex'))
.body;
assert.equal(first.pageSize, pageSize);
assert.equal(first.items.length, pageSize);
assert.equal(last.page, Math.ceil(31 / pageSize));
assert.equal(last.items.length, 31 % pageSize);
}
assert.equal((await request(`/merchants?${query}&ownerId=user-manager2`, 'alex')).status, 403);
assert.equal(
(await request(`/merchants?search=${prefix}&ownerId=user-manager2`, 'head')).body.items[0].id,
@@ -190,7 +199,17 @@ test('search, combined filters, pagination and metadata apply ownership scope be
unassigned,
);
assert.equal((await request(`/merchants?search=${prefix}&country=JP`, 'alex')).body.total, 0);
for (const invalid of ['country=ZZ', 'industry=INVALID', 'status=Live', 'page=1.5', 'page=-1'])
for (const invalid of [
'country=ZZ',
'industry=INVALID',
'status=Live',
'page=1.5',
'page=-1',
'pageSize=8',
'pageSize=0',
'pageSize=15',
'pageSize=1000',
])
assert.equal((await request(`/merchants?${invalid}`)).status, 400);
const ownFilters = merchantFiltersSchema.parse(
(await request('/merchants/filters', 'alex')).body,
+10 -3
View File
@@ -172,12 +172,19 @@ function SalesDashboard({ data, user }: { data: Data; user: User }) {
<div className="grid grid-cols-2 gap-3 sm:grid-cols-3 xl:grid-cols-9">
{data.distribution.map((d) => (
<Link
className="min-h-11 rounded-md p-1"
className="flex min-h-11 flex-col gap-2 rounded-md p-1"
key={d.status}
to={`/app/merchants?status=${d.status}`}
>
<span className="text-xs text-muted-foreground">{t(`statuses.${d.status}`)}</span>
<span className="mt-2 block text-lg font-semibold tabular-nums">
<span className="flex items-start gap-2 text-xs text-muted-foreground">
<span
className="mt-1 size-2 shrink-0 rounded-full"
style={{ backgroundColor: stageColors[d.status] }}
aria-hidden="true"
/>
<span>{t(`statuses.${d.status}`)}</span>
</span>
<span className="mt-auto block text-lg font-semibold tabular-nums">
{f.number(d.count)}
</span>
</Link>
+53 -31
View File
@@ -1,7 +1,7 @@
import { useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useMutation } from '@tanstack/react-query';
import { useForm } from 'react-hook-form';
import { Controller, useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { ArrowUpRight, Check, LoaderCircle } from 'lucide-react';
import {
@@ -13,7 +13,7 @@ import {
type PublicLeadInput,
} from '@merchantflow/contracts';
import { Input } from '@merchantflow/ui/components/input';
import { NativeSelect } from '@merchantflow/ui/components/native-select';
import { Select, SelectOption } from '@merchantflow/ui/components/select';
import { FormField } from '@merchantflow/ui/components/form-field';
import { Button } from '@merchantflow/ui/components/button';
import { api, ApiError } from '../lib/api';
@@ -202,37 +202,59 @@ export function LeadForm() {
</FormField>
))}
<FormField id="lead-country" label={t('landing.country')} error={errorText('country')}>
<NativeSelect
{...form.register('country')}
{...accessibility('country')}
autoComplete="country"
className="w-full"
>
<option value="" disabled>
{t('landing.countryPlaceholder')}
</option>
{countries.map(({ code, name }) => (
<option key={code} value={code}>
{name}
</option>
))}
</NativeSelect>
<Controller
name="country"
control={form.control}
render={({ field }) => (
<Select
name={field.name}
disabled={mutation.isPending}
ref={field.ref}
value={field.value ?? ''}
onValueChange={field.onChange}
onBlur={field.onBlur}
{...accessibility('country')}
autoComplete="country"
className="w-full"
>
<SelectOption value="" disabled>
{t('landing.countryPlaceholder')}
</SelectOption>
{countries.map(({ code, name }) => (
<SelectOption key={code} value={code}>
{name}
</SelectOption>
))}
</Select>
)}
/>
</FormField>
<FormField id="lead-industry" label={t('landing.industry')} error={errorText('industry')}>
<NativeSelect
{...form.register('industry')}
{...accessibility('industry')}
className="w-full"
>
<option value="" disabled>
{t('landing.industryPlaceholder')}
</option>
{industries.map((industry) => (
<option key={industry} value={industry}>
{t(`industry.${industry}`)}
</option>
))}
</NativeSelect>
<Controller
name="industry"
control={form.control}
render={({ field }) => (
<Select
name={field.name}
disabled={mutation.isPending}
ref={field.ref}
value={field.value ?? ''}
onValueChange={field.onChange}
onBlur={field.onBlur}
{...accessibility('industry')}
className="w-full"
>
<SelectOption value="" disabled>
{t('landing.industryPlaceholder')}
</SelectOption>
{industries.map((industry) => (
<SelectOption key={industry} value={industry}>
{t(`industry.${industry}`)}
</SelectOption>
))}
</Select>
)}
/>
</FormField>
<div className="lead-volume">
<FormField
+1
View File
@@ -74,6 +74,7 @@ export function ReminderInbox() {
<TaskRow task={task} onNavigate={() => setOpen(false)} />
<Button
variant="outline"
className="mt-3"
disabled={dismissal.isPending}
onClick={() => dismissal.mutate(task)}
>
+1 -1
View File
@@ -140,7 +140,7 @@ export function ActionableTask({ task }: { task: Task }) {
return (
<div id={`task-${task.id}`} className="border-t first:border-0 scroll-mt-5">
<TaskRow task={task} />
<div className="flex flex-wrap items-center gap-2 px-5 pb-4">
<div className="flex flex-wrap items-center gap-2 px-5 py-4">
{task.capabilities.edit && (
<Button variant="outline" onClick={() => setEditing(task)}>
{t('workflow.editTask')}
+25 -9
View File
@@ -1,5 +1,5 @@
import { useId, useState, type ReactNode } from 'react';
import { useForm } from 'react-hook-form';
import { Controller, useForm } from 'react-hook-form';
import { useMutation } from '@tanstack/react-query';
import { useTranslation } from 'react-i18next';
import { z } from 'zod';
@@ -11,7 +11,7 @@ import {
SheetDescription,
} from '@merchantflow/ui/components/sheet';
import { Input } from '@merchantflow/ui/components/input';
import { NativeSelect } from '@merchantflow/ui/components/native-select';
import { Select, SelectOption } from '@merchantflow/ui/components/select';
import { FormField } from '@merchantflow/ui/components/form-field';
import { api, ApiError, queryClient } from '../lib/api';
import { Button } from './shared';
@@ -107,13 +107,29 @@ export function Editor({
error={errors[field.name]}
>
{field.options ? (
<NativeSelect {...props}>
{field.options.map((option) => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))}
</NativeSelect>
<Controller
name={field.name}
control={form.control}
render={({ field: control }) => (
<Select
id={fieldId}
name={control.name}
ref={control.ref}
value={control.value ?? ''}
onValueChange={control.onChange}
onBlur={control.onBlur}
disabled={pending || field.disabled}
aria-invalid={!!errors[field.name]}
aria-describedby={props['aria-describedby']}
>
{field.options!.map((option) => (
<SelectOption key={option.value} value={option.value}>
{option.label}
</SelectOption>
))}
</Select>
)}
/>
) : field.type === 'textarea' ? (
<textarea
{...props}
+12
View File
@@ -17,6 +17,18 @@ it('canonicalizes invalid/default query values while retaining search typing and
).toBe('');
expect(directoryParams(new URLSearchParams('page=1'), 'HEAD_OF_SALES').toString()).toBe('');
});
it('retains supported page sizes and drops unsupported values', () => {
for (const size of ['10', '20', '30'])
expect(
directoryParams(new URLSearchParams(`pageSize=${size}&page=2`), 'HEAD_OF_SALES').get(
'pageSize',
),
).toBe(size);
for (const size of ['8', '15', '0', '1000', 'invalid'])
expect(
directoryParams(new URLSearchParams(`pageSize=${size}`), 'HEAD_OF_SALES').has('pageSize'),
).toBe(false);
});
it('removes owner controls from manager URLs without dropping the rest of their search', () => {
const result = directoryParams(
new URLSearchParams('search=hello&ownerId=user-manager2&country=GB&page=3'),
+1
View File
@@ -11,6 +11,7 @@ export function directoryParams(input: URLSearchParams, role: Role) {
'industry',
'ownerId',
'page',
'pageSize',
'createdFrom',
'createdTo',
'cohort',
+2
View File
@@ -27,6 +27,7 @@ export const en = {
next: 'Next',
page: 'Page {{page}} of {{total}}',
showing: '{{from}}–{{to}} of {{total}} merchants',
perPage: 'Show per page',
all: 'All',
language: 'Language',
logout: 'Sign out',
@@ -262,6 +263,7 @@ export const ru = {
next: 'Далее',
page: 'Страница {{page}} из {{total}}',
showing: '{{from}}–{{to}} из {{total}} мерчантов',
perPage: 'На странице',
all: 'Все',
language: 'Язык',
logout: 'Выйти',
+60 -44
View File
@@ -38,7 +38,7 @@ import {
type Merchant,
} from '@merchantflow/contracts';
import { Input } from '@merchantflow/ui/components/input';
import { NativeSelect } from '@merchantflow/ui/components/native-select';
import { Select, SelectOption } from '@merchantflow/ui/components/select';
import {
Table,
TableHeader,
@@ -245,75 +245,77 @@ export function Merchants() {
aria-label={t('workspace.filters')}
className="grid gap-2 sm:grid-cols-2 xl:grid-cols-4"
>
<NativeSelect
<Select
aria-label={t('merchants.filter')}
value={status}
onChange={(e) => update('status', e.target.value)}
onValueChange={(value) => update('status', value)}
className="w-full bg-white sm:min-w-[190px]"
>
<option value="">{t('merchants.allStages')}</option>
<SelectOption value="">{t('merchants.allStages')}</SelectOption>
{statuses.map((s) => (
<option key={s} value={s}>
<SelectOption key={s} value={s}>
{t(`statuses.${s}`)}
</option>
</SelectOption>
))}
</NativeSelect>
<NativeSelect
</Select>
<Select
className="w-full bg-white"
aria-label={t('workspace.allCountries')}
value={normalized.get('country') ?? ''}
onChange={(event) => update('country', event.target.value)}
onValueChange={(value) => update('country', value)}
>
<option value="">{t('workspace.allCountries')}</option>
<SelectOption value="">{t('workspace.allCountries')}</SelectOption>
{[
...new Set([
...(filters.data?.countries ?? []),
...(normalized.get('country') ? [normalized.get('country')!] : []),
]),
].map((country) => (
<option key={country} value={country}>
<SelectOption key={country} value={country}>
{f.country(country)}
</option>
</SelectOption>
))}
</NativeSelect>
<NativeSelect
</Select>
<Select
className="w-full bg-white"
aria-label={t('workspace.allIndustries')}
value={normalized.get('industry') ?? ''}
onChange={(event) => update('industry', event.target.value)}
onValueChange={(value) => update('industry', value)}
>
<option value="">{t('workspace.allIndustries')}</option>
<SelectOption value="">{t('workspace.allIndustries')}</SelectOption>
{[
...new Set([
...(filters.data?.industries ?? []),
...(normalized.get('industry') ? [normalized.get('industry')!] : []),
]),
].map((industry) => (
<option key={industry} value={industry}>
<SelectOption key={industry} value={industry}>
{t(`industry.${industry}`)}
</option>
</SelectOption>
))}
</NativeSelect>
</Select>
{filters.data?.canFilterOwner && (
<NativeSelect
<Select
className="w-full bg-white"
aria-label={t('workspace.allOwners')}
value={normalized.get('ownerId') ?? ''}
onChange={(event) => update('ownerId', event.target.value)}
onValueChange={(value) => update('ownerId', value)}
>
<option value="">{t('workspace.allOwners')}</option>
<option value="unassigned">{t('workflow.unassigned')}</option>
<SelectOption value="">{t('workspace.allOwners')}</SelectOption>
<SelectOption value="unassigned">{t('workflow.unassigned')}</SelectOption>
{filters.data.owners.map((owner) => (
<option key={owner.id} value={owner.id}>
<SelectOption key={owner.id} value={owner.id}>
{owner.name}
</option>
</SelectOption>
))}
{normalized.get('ownerId') &&
normalized.get('ownerId') !== 'unassigned' &&
!filters.data.owners.some((owner) => owner.id === normalized.get('ownerId')) && (
<option value={normalized.get('ownerId')!}>{t('workspace.notProvided')}</option>
<SelectOption value={normalized.get('ownerId')!}>
{t('workspace.notProvided')}
</SelectOption>
)}
</NativeSelect>
</Select>
)}
</div>
</div>
@@ -363,6 +365,20 @@ export function Merchants() {
total: f.number(data.total),
})}
</p>
<label className="flex items-center gap-2 text-xs text-muted-foreground sm:ml-auto">
<span>{t('common.perPage')}</span>
<Select
className="w-20 bg-white"
value={normalized.get('pageSize') ?? '10'}
onValueChange={(value) => update('pageSize', value)}
>
{['10', '20', '30'].map((value) => (
<SelectOption key={value} value={value}>
{f.number(Number(value))}
</SelectOption>
))}
</Select>
</label>
<nav
aria-label={t('common.page', {
page: f.number(page),
@@ -677,19 +693,19 @@ export function Pipeline() {
<QueryBoundary query={query}>
{(merchants) => (
<>
<NativeSelect
<Select
className="mb-5 w-full md:hidden"
aria-label={t('pipeline.stageSelect')}
value={stage}
onChange={(event) => setParams({ stage: event.target.value })}
onValueChange={(value) => setParams({ stage: value })}
>
{statuses.map((value) => (
<option key={value} value={value}>
<SelectOption key={value} value={value}>
{t(`statuses.${value}`)} (
{f.number(merchants.filter((merchant) => merchant.status === value).length)})
</option>
</SelectOption>
))}
</NativeSelect>
</Select>
<div
className="flex gap-4 overflow-x-auto pb-4"
aria-label={t('pipeline.title')}
@@ -813,39 +829,39 @@ export function ReviewQueue() {
</label>
<label className="space-y-2 text-xs text-muted-foreground">
<span>{t('common.owner')}</span>
<NativeSelect
<Select
className="w-full"
value={filters.get('ownerId') ?? ''}
onChange={(event) => update('ownerId', event.target.value)}
onValueChange={(value) => update('ownerId', value)}
>
<option value="">{t('workspace.allOwners')}</option>
<option value="unassigned">{t('workflow.unassigned')}</option>
<SelectOption value="">{t('workspace.allOwners')}</SelectOption>
<SelectOption value="unassigned">{t('workflow.unassigned')}</SelectOption>
{query.data?.owners.map((owner) => (
<option key={owner.id} value={owner.id}>
<SelectOption key={owner.id} value={owner.id}>
{owner.name}
</option>
</SelectOption>
))}
</NativeSelect>
</Select>
</label>
<label className="space-y-2 text-xs text-muted-foreground">
<span>{t(decided ? 'workflow.decision' : 'onboarding.waitingTime')}</span>
<NativeSelect
<Select
className="w-full"
value={filters.get(decided ? 'decision' : 'waiting') ?? 'ALL'}
onChange={(event) => update(decided ? 'decision' : 'waiting', event.target.value)}
onValueChange={(value) => update(decided ? 'decision' : 'waiting', value)}
>
{(decided ? ['ALL', 'APPROVED', 'CORRECTIONS', 'REJECTED'] : ['ALL', '24', '72']).map(
(value) => (
<option key={value} value={value}>
<SelectOption key={value} value={value}>
{t(
decided && value !== 'ALL'
? `workflow.${value}`
: `onboarding.waiting.${value}`,
)}
</option>
</SelectOption>
),
)}
</NativeSelect>
</Select>
</label>
</section>
<QueryBoundary query={query}>
+1 -1
View File
@@ -294,7 +294,7 @@
min-width: 0;
}
.lead-fields input,
.lead-fields select {
.lead-fields [data-slot='select-trigger'] {
background: #fcfdf9;
min-height: 48px;
}