Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ describe('ID 검색 파라미터 정밀도', () => {
'/_authed/_shell/reviews accountId',
'/_authed/_shell/reviews reviewId',
'/_authed/_shell/reviews storeId',
'/_authed/_shell/settlements/ storeId',
'/_authed/_shell/stores/ regionId',
].sort(),
);
Expand Down
3 changes: 3 additions & 0 deletions src/app/shell/nav.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ describe('nav', () => {
{ path: '/notifications/send', want: '알림' },
{ path: '/banners/5', want: '배너' },
{ path: '/search-chips', want: '검색 칩' },
{ path: '/settlements/monthly', want: '정산' },
{ path: '/settlements/31', want: '정산' },
{ path: '/settings', want: '결제 설정' },
])('하위 화면도 메뉴 제목을 따른다: $path → $want', ({ path, want }) => {
expect(titleFor(path)).toBe(want);
});
Expand Down
8 changes: 7 additions & 1 deletion src/app/shell/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@ import {
MapPinIcon,
ScrollTextIcon,
SearchIcon,
SettingsIcon,
ShieldIcon,
MessageSquareIcon,
MessagesSquareIcon,
ShoppingBagIcon,
StoreIcon,
UsersIcon,
WalletIcon,
} from 'lucide-react';

/** 사이드바 메뉴. 각 영역 PR이 자기 항목을 붙인다 — Link의 to가 라우트 타입으로 검사되므로 있는 경로만 둔다. */
interface NavItem {
to:
| '/'
| '/orders'
| '/settlements'
| '/users'
| '/sellers'
| '/stores'
Expand All @@ -38,7 +41,8 @@ interface NavItem {
| '/notifications'
| '/regions'
| '/audit-logs'
| '/admins';
| '/admins'
| '/settings';
label: string;
icon: LucideIcon;
}
Expand All @@ -53,6 +57,7 @@ export const NAV_GROUPS: NavGroup[] = [
label: '운영',
items: [
{ to: '/orders', label: '주문', icon: ShoppingBagIcon },
{ to: '/settlements', label: '정산', icon: WalletIcon },
{ to: '/reports', label: '신고', icon: FlagIcon },
{ to: '/reviews', label: '리뷰', icon: MessageSquareIcon },
{ to: '/review-comments', label: '리뷰 댓글', icon: MessagesSquareIcon },
Expand Down Expand Up @@ -80,6 +85,7 @@ export const NAV_GROUPS: NavGroup[] = [
],
},
{ label: '기록', items: [{ to: '/audit-logs', label: '감사 로그', icon: ScrollTextIcon }] },
{ label: '설정', items: [{ to: '/settings', label: '결제 설정', icon: SettingsIcon }] },
];

export function titleFor(pathname: string): string {
Expand Down
19 changes: 16 additions & 3 deletions src/features/accounts/components/account-status-actions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { type ReactNode, useState } from 'react';
import { toast } from 'sonner';

import { type AccountStatus } from '@/graphql/generated/graphql';
Expand Down Expand Up @@ -28,10 +28,21 @@ interface Props {
label: string;
/** 성공 뒤 호출자의 캐시 무효화 */
onChanged: () => Promise<void> | void;
/** 정지 다이얼로그에 덧붙일 내용(판매자: 진행 주문 경고·매장도 숨기기) */
suspendExtra?: ReactNode;
/** 정지 성공 뒤 이어서 할 일. 실패 안내는 스스로 하고 던지지 않는다 — 정지는 이미 됐다 */
afterSuspend?: (reason: string) => Promise<void>;
}

/** USER·SELLER 공용 정지/정지 해제. 정지는 사유 필수(감사 로그), 해제는 확인만. */
export function AccountStatusActions({ accountId, status, label, onChanged }: Props) {
export function AccountStatusActions({
accountId,
status,
label,
onChanged,
suspendExtra,
afterSuspend,
}: Props) {
const [open, setOpen] = useState(false);
const [reason, setReason] = useState('');
const [busy, setBusy] = useState(false);
Expand Down Expand Up @@ -62,8 +73,9 @@ export function AccountStatusActions({ accountId, status, label, onChanged }: Pr
setBusy(true);
try {
await suspendAccount(accountId, trimmed);
await onChanged();
toast.success(`${label} 계정을 정지했습니다.`);
await afterSuspend?.(trimmed);
await onChanged();
setOpen(false);
setReason('');
} catch (e) {
Expand All @@ -86,6 +98,7 @@ export function AccountStatusActions({ accountId, status, label, onChanged }: Pr
즉시 로그아웃되고 앱·판매자 센터를 이용할 수 없게 됩니다. 사유는 감사 로그에 남습니다.
</DialogDescription>
</DialogHeader>
{suspendExtra}
<div className="flex flex-col gap-1.5">
<Label htmlFor="suspend-reason">정지 사유 (필수)</Label>
<Textarea
Expand Down
2 changes: 2 additions & 0 deletions src/features/accounts/pages/users.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ describe('구매자', () => {
const dialog = await screen.findByRole('dialog');
expect(dialog).toHaveTextContent('즉시 로그아웃되고 앱·판매자 센터를 이용할 수 없게 됩니다.');
expect(dialog).not.toHaveTextContent('API');
// 매장도 숨기기는 판매자 정지에만 있다
expect(within(dialog).queryByRole('checkbox')).not.toBeInTheDocument();
expect(within(dialog).getByRole('button', { name: '계정 정지' })).toBeDisabled();
await userEvent.type(within(dialog).getByLabelText('정지 사유 (필수)'), ' 욕설 신고 누적 ');
await userEvent.click(within(dialog).getByRole('button', { name: '계정 정지' }));
Expand Down
35 changes: 34 additions & 1 deletion src/features/audit-logs/components/audit-links.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ import { actorTypeLabel, targetLabel } from '../meta';
const linkClass = 'text-primary-soft-foreground hover:underline';

/** 대상 종류별 화면으로 잇는다. 상세 화면이 없는 종류(계정·분류·지역·알림 등)는 글자만 보인다 */
export function TargetLink({ targetType, targetId }: { targetType: string; targetId: string }) {
export function TargetLink({
targetType,
targetId,
storeId,
}: {
targetType: string;
targetId: string;
storeId?: string | null;
}) {
const text = `${targetLabel(targetType)} #${targetId}`;
switch (targetType) {
case 'ORDER':
Expand Down Expand Up @@ -45,6 +53,31 @@ export function TargetLink({ targetType, targetId }: { targetType: string; targe
{text}
</Link>
);
case 'SETTLEMENT':
return (
<Link
to="/settlements/$settlementId"
params={{ settlementId: targetId }}
className={linkClass}
>
{text}
</Link>
);
case 'PAYMENT_SETTING':
return (
<Link to="/settings" className={linkClass}>
{text}
</Link>
);
case 'SETTLEMENT_ACCOUNT':
// targetId는 계좌 행 번호라 화면이 없다. 계좌는 매장 상세에서 본다
return storeId == null ? (
<span>{text}</span>
) : (
<Link to="/stores/$storeId" params={{ storeId }} className={linkClass}>
{text}
</Link>
);
default:
return <span>{text}</span>;
}
Expand Down
6 changes: 5 additions & 1 deletion src/features/audit-logs/pages/audit-logs-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ const columns: ColumnDef<AuditRow, unknown>[] = [
id: 'target',
header: '대상',
cell: ({ row }) => (
<TargetLink targetType={row.original.targetType} targetId={row.original.targetId} />
<TargetLink
targetType={row.original.targetType}
targetId={row.original.targetId}
storeId={row.original.storeId}
/>
),
},
{
Expand Down
19 changes: 19 additions & 0 deletions src/features/audit-logs/pages/audit-logs.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ describe('감사 로그', () => {
['REVIEW_COMMENT', '리뷰 댓글 #5', null],
['NOTIFICATION', '알림 #5', null],
['CONVERSATION', '대화 #5', null],
['SETTLEMENT', '정산 #5', '/settlements/5'],
['PAYMENT_SETTING', '결제 설정 #5', '/settings'],
// 계좌 행 번호라 화면이 없어 기록의 매장(17)으로 간다
['SETTLEMENT_ACCOUNT', '정산 계좌 #5', '/stores/17'],
])('대상 %s는 "%s" → %s', async (targetType, text, href) => {
server.use(
gqlOk('AdminAuditLogs', {
Expand All @@ -156,6 +160,21 @@ describe('감사 로그', () => {
else expect(decodeURIComponent(cell.closest('a')!.getAttribute('href')!)).toBe(href);
});

it('매장이 없는 정산 계좌 기록은 글자만 보인다', async () => {
server.use(
gqlOk('AdminAuditLogs', {
adminAuditLogs: {
items: [{ ...log, targetType: 'SETTLEMENT_ACCOUNT', targetId: '5', storeId: null }],
totalCount: 1,
hasMore: false,
nextCursor: null,
},
}),
);
boot('/audit-logs');
expect((await screen.findByText('정산 계좌 #5')).closest('a')).toBeNull();
});

it.each([
['SELLER', '판매자', '/sellers/3'],
['USER', '구매자', '/users/3'],
Expand Down
70 changes: 70 additions & 0 deletions src/features/sellers/components/seller-status-actions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { useQueryClient } from '@tanstack/react-query';
import { useState } from 'react';
import { toast } from 'sonner';

import { AccountStatusActions } from '@/features/accounts';
import { InProgressOrdersWarning, setStoreActive } from '@/features/stores';
import { type AccountStatus } from '@/graphql/generated/graphql';
import { messageFor } from '@/shared/api';
import { Checkbox } from '@/shared/ui/checkbox';
import { Label } from '@/shared/ui/label';

interface Props {
accountId: string;
status: AccountStatus;
label: string;
store: { id: string; isActive: boolean } | null | undefined;
onChanged: () => Promise<void>;
}

/**
* 판매자 정지. 매장 진행 주문을 경고하고, '매장도 숨기기'(기본 켬)면 정지 뒤 매장을 숨긴다.
* 숨기기가 실패해도 정지는 되돌리지 않고 알리기만 한다 — 매장 화면에서 다시 숨기면 된다.
*/
export function SellerStatusActions({ accountId, status, label, store, onChanged }: Props) {
const queryClient = useQueryClient();
const [hideStore, setHideStore] = useState(true);
// 정지·해제를 거치면 다음 정지는 다시 기본값(켬)에서 시작한다
const [shownStatus, setShownStatus] = useState(status);
if (shownStatus !== status) {
setShownStatus(status);
setHideStore(true);
}
const canHide = store?.isActive === true;
return (
<AccountStatusActions
accountId={accountId}
status={status}
label={label}
onChanged={onChanged}
suspendExtra={
store && (
<>
<InProgressOrdersWarning storeId={store.id} />
{canHide && (
<div className="flex items-center gap-2">
<Checkbox
id="suspend-hide-store"
checked={hideStore}
onCheckedChange={(v) => setHideStore(v === true)}
/>
<Label htmlFor="suspend-hide-store">매장도 숨기기</Label>
</div>
)}
</>
)
}
afterSuspend={
store && canHide && hideStore
? async (reason) => {
try {
await setStoreActive(queryClient, store.id, false, reason);
} catch (e) {
toast.error(`계정은 정지했지만 매장을 숨기지 못했습니다. ${messageFor(e)}`);
}
}
: undefined
}
/>
);
}
11 changes: 4 additions & 7 deletions src/features/sellers/pages/seller-detail-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import { useQuery, useQueryClient } from '@tanstack/react-query';
import { Link } from '@tanstack/react-router';
import { HistoryIcon } from 'lucide-react';

import {
accountLabel,
AccountStatusActions,
AccountStatusPill,
ResetPasswordDialog,
} from '@/features/accounts';
import { accountLabel, AccountStatusPill, ResetPasswordDialog } from '@/features/accounts';
import { messageFor } from '@/shared/api';
import { formatKst } from '@/shared/lib/kst';
import { Button } from '@/shared/ui/button';
Expand All @@ -17,6 +12,7 @@ import { Skeleton } from '@/shared/ui/skeleton';
import { StatusPill } from '@/shared/ui/status-pill';

import { invalidateSellers, resetSellerPassword, sellerDetailQueryOptions } from '../api/queries';
import { SellerStatusActions } from '../components/seller-status-actions';
import { StoreVisibilityPill } from '../components/store-visibility-pill';

const BACK = { to: '/sellers' } as const;
Expand Down Expand Up @@ -66,10 +62,11 @@ export function SellerDetailPage({ accountId }: { accountId: string }) {
await refresh();
}}
/>
<AccountStatusActions
<SellerStatusActions
accountId={s.accountId}
status={s.status}
label={label}
store={s.store}
onChanged={refresh}
/>
</>
Expand Down
Loading