feat: 가맹몰 상세 등록 화면을 분리하고 목록은 상세가 있는 가맹점만 보여 준다
[+ 업체 등록]은 /system/merchant-details/new로 간다 — 업체명 자리에서 상세가 없는 가맹점을 고르면 연락처·주소가 채워지고 나머지는 같은 폼이다(사용자 확정). 행의 [수정]은 언제나 수정 화면이 되도록 목록에는 상세가 등록된 가맹점만 세운다 — 백엔드 목록에 그 조건이 없어 Repository가 전 페이지를 받아 거르고 화면 쪽 페이지로 자른다(TODO 백엔드). 상세가 없는 가맹점의 수정 주소로 들어오면 등록 화면으로 보내 미리 골라 둔다. Co-Authored-By: Claude Opus 5
@276b625d8ae7452f8017af2080194533d6c2f97c
--- app/(protected)/(basic)/system/merchant-details/[frcsNo]/_components/merchant-detail-form.tsx
+++ app/(protected)/(basic)/system/merchant-details/[frcsNo]/_components/merchant-detail-form.tsx
... | ... | @@ -21,6 +21,7 @@ |
| 21 | 21 |
formatMerchantDetailStatusLabel, |
| 22 | 22 |
formatOptionalValue, |
| 23 | 23 |
type MerchantDetail, |
| 24 |
+ type MerchantDetailSummary, |
|
| 24 | 25 |
} from '@/lib/domain/merchant-detail'; |
| 25 | 26 |
import {
|
| 26 | 27 |
CLOSED_DAYS_MAX_LENGTH, |
... | ... | @@ -42,19 +43,30 @@ |
| 42 | 43 |
import styles from './merchant-detail-form.module.scss'; |
| 43 | 44 |
|
| 44 | 45 |
interface MerchantDetailFormProps {
|
| 45 |
- detail: MerchantDetail; |
|
| 46 |
- products: MerchantProduct[]; |
|
| 46 |
+ /** 수정 — 상세가 있는 가맹점. 없으면 등록 화면이다. */ |
|
| 47 |
+ detail?: MerchantDetail; |
|
| 48 |
+ /** 등록 — 아직 상세가 없는 가맹점 선택지. 업체명 자리에서 하나를 고른다. */ |
|
| 49 |
+ candidates?: MerchantDetailSummary[]; |
|
| 50 |
+ /** 등록 — 미리 골라 둘 가맹점(`?frcsNo=`). */ |
|
| 51 |
+ initialFrcsNo?: string; |
|
| 52 |
+ products?: MerchantProduct[]; |
|
| 47 | 53 |
categories: CommonCode[]; |
| 48 | 54 |
} |
| 49 | 55 |
|
| 50 | 56 |
/** |
| 51 |
- * 가맹몰 상세 등록·수정 — 기획 BO-MAL-002(등록)·003(수정)을 한 화면으로 합쳤다. 상세는 |
|
| 52 |
- * 가맹점당 하나라 `frcsNo`만으로 등록인지 수정인지 갈린다(`detail.hasDetail`). |
|
| 57 |
+ * 가맹몰 상세 등록·수정 — 기획 BO-MAL-002(등록)·003(수정). `detail`이 있으면 수정, 없으면 등록이다. |
|
| 53 | 58 |
* |
| 54 |
- * 업체명·연락처·우편번호·주소는 가맹점 원본이라 읽기 전용이다(사용자 확정). 기획의 [주소 검색]은 |
|
| 55 |
- * 가맹점 관리 화면의 것이고 여기서는 값을 바꾸지 않는다. |
|
| 59 |
+ * 상세는 기존 가맹점에만 붙으므로 등록 화면은 업체명 자리에서 상세가 없는 가맹점을 고른다 |
|
| 60 |
+ * (사용자 확정). 업체명·연락처·우편번호·주소는 가맹점 원본이라 읽기 전용이고, 기획의 [주소 검색]은 |
|
| 61 |
+ * 가맹점 관리 화면의 것이라 여기서는 값을 바꾸지 않는다. |
|
| 56 | 62 |
*/ |
| 57 |
-export function MerchantDetailForm({ detail, products, categories }: MerchantDetailFormProps) {
|
|
| 63 |
+export function MerchantDetailForm({
|
|
| 64 |
+ detail, |
|
| 65 |
+ candidates = [], |
|
| 66 |
+ initialFrcsNo, |
|
| 67 |
+ products = [], |
|
| 68 |
+ categories, |
|
| 69 |
+}: MerchantDetailFormProps) {
|
|
| 58 | 70 |
const router = useRouter(); |
| 59 | 71 |
const { showAlert, hideAlert, showToast } = useFeedback();
|
| 60 | 72 |
const [isBusy, startAction] = useBlockingAction(); |
... | ... | @@ -62,16 +74,21 @@ |
| 62 | 74 |
saveMerchantDetailAction, |
| 63 | 75 |
INITIAL_MERCHANT_DETAIL_FORM_STATE |
| 64 | 76 |
); |
| 65 |
- const isEdit = detail.hasDetail; |
|
| 77 |
+ const isEdit = detail !== undefined; |
|
| 66 | 78 |
const errors = state.status === 'error' ? (state.errors ?? {}) : {};
|
| 67 | 79 |
|
| 68 |
- const [categoryCode, setCategoryCode] = useState(detail.categoryCode ?? ''); |
|
| 80 |
+ const [frcsNo, setFrcsNo] = useState(detail?.id ?? initialFrcsNo ?? ''); |
|
| 81 |
+ // 읽기 전용 칸의 출처 — 수정은 상세, 등록은 고른 가맹점. |
|
| 82 |
+ const merchant: MerchantDetailSummary | null = |
|
| 83 |
+ detail ?? candidates.find((row) => row.id === frcsNo) ?? null; |
|
| 84 |
+ const [categoryCode, setCategoryCode] = useState(detail?.categoryCode ?? ''); |
|
| 69 | 85 |
const [visibility, setVisibility] = useState<string[]>([ |
| 70 |
- detail.isVisible === false ? 'N' : 'Y', |
|
| 86 |
+ detail?.isVisible === false ? 'N' : 'Y', |
|
| 71 | 87 |
]); |
| 72 | 88 |
const [voucherUse, setVoucherUse] = useState<string[]>(['Y']); |
| 73 | 89 |
|
| 74 | 90 |
function toggleVisibility() {
|
| 91 |
+ if (!detail) return; |
|
| 75 | 92 |
const next = detail.isVisible === false; |
| 76 | 93 |
startAction(async () => {
|
| 77 | 94 |
const result = await updateMerchantDetailVisibilityAction(detail.id, next); |
... | ... | @@ -84,6 +101,7 @@ |
| 84 | 101 |
} |
| 85 | 102 |
|
| 86 | 103 |
function runDelete() {
|
| 104 |
+ if (!detail) return; |
|
| 87 | 105 |
hideAlert(); |
| 88 | 106 |
startAction(async () => {
|
| 89 | 107 |
const result = await deleteMerchantDetailAction(detail.id); |
... | ... | @@ -97,6 +115,7 @@ |
| 97 | 115 |
} |
| 98 | 116 |
|
| 99 | 117 |
function confirmDelete() {
|
| 118 |
+ if (!detail) return; |
|
| 100 | 119 |
showAlert({
|
| 101 | 120 |
variant: 'danger', |
| 102 | 121 |
title: '가맹몰 상세를 삭제하시겠습니까?', |
... | ... | @@ -132,13 +151,35 @@ |
| 132 | 151 |
onSubmit={(event) => submitFormAction(event, formAction)}
|
| 133 | 152 |
className={styles.form}
|
| 134 | 153 |
> |
| 135 |
- <input type="hidden" name="frcsNo" value={detail.id} />
|
|
| 154 |
+ <input type="hidden" name="frcsNo" value={frcsNo} />
|
|
| 136 | 155 |
<input type="hidden" name="mode" value={isEdit ? 'edit' : 'create'} />
|
| 137 | 156 |
|
| 138 | 157 |
<FoxCard size="lg" title="기본 정보" className={styles.section}>
|
| 139 | 158 |
<div className={styles.grid}>
|
| 140 | 159 |
<div className={styles.fieldWide}>
|
| 141 |
- <FoxInput size="md" label="업체명" requirement="required" value={detail.name} readOnly state="view" />
|
|
| 160 |
+ {detail ? (
|
|
| 161 |
+ <FoxInput size="md" label="업체명" requirement="required" value={detail.name} readOnly state="view" />
|
|
| 162 |
+ ) : ( |
|
| 163 |
+ <> |
|
| 164 |
+ <FoxSelect |
|
| 165 |
+ size="md" |
|
| 166 |
+ label="업체명" |
|
| 167 |
+ requirement="required" |
|
| 168 |
+ placeholder="상세를 등록할 가맹점 선택" |
|
| 169 |
+ options={candidates.map((row) => ({ value: row.id, label: row.name }))}
|
|
| 170 |
+ value={frcsNo}
|
|
| 171 |
+ onValueChange={setFrcsNo}
|
|
| 172 |
+ error={Boolean(errors.frcsNo)}
|
|
| 173 |
+ /> |
|
| 174 |
+ {errors.frcsNo && <FoxHelperText type="danger" message={errors.frcsNo} />}
|
|
| 175 |
+ {candidates.length === 0 && (
|
|
| 176 |
+ <FoxHelperText |
|
| 177 |
+ type="information" |
|
| 178 |
+ message="상세를 붙일 가맹점이 없습니다. 가맹점 관리에서 먼저 등록해 주세요." |
|
| 179 |
+ /> |
|
| 180 |
+ )} |
|
| 181 |
+ </> |
|
| 182 |
+ )} |
|
| 142 | 183 |
</div> |
| 143 | 184 |
<div className={styles.field}>
|
| 144 | 185 |
<FoxSelect |
... | ... | @@ -159,7 +200,7 @@ |
| 159 | 200 |
size="md" |
| 160 | 201 |
label="업체 연락처" |
| 161 | 202 |
requirement="required" |
| 162 |
- value={formatOptionalValue(formatPhoneNumber(detail.phoneNumber))}
|
|
| 203 |
+ value={formatOptionalValue(formatPhoneNumber(merchant?.phoneNumber ?? null))}
|
|
| 163 | 204 |
readOnly |
| 164 | 205 |
state="view" |
| 165 | 206 |
/> |
... | ... | @@ -168,13 +209,13 @@ |
| 168 | 209 |
|
| 169 | 210 |
<div className={styles.grid}>
|
| 170 | 211 |
<div className={styles.fieldNarrow}>
|
| 171 |
- <FoxInput size="md" label="우편번호" requirement="required" value={formatOptionalValue(detail.postalCode)} readOnly state="view" />
|
|
| 212 |
+ <FoxInput size="md" label="우편번호" requirement="required" value={formatOptionalValue(detail?.postalCode)} readOnly state="view" />
|
|
| 172 | 213 |
</div> |
| 173 | 214 |
<div className={styles.fieldWide}>
|
| 174 |
- <FoxInput size="md" label="주소" value={formatOptionalValue(detail.address)} readOnly state="view" />
|
|
| 215 |
+ <FoxInput size="md" label="주소" value={formatOptionalValue(merchant?.address)} readOnly state="view" />
|
|
| 175 | 216 |
</div> |
| 176 | 217 |
<div className={styles.field}>
|
| 177 |
- <FoxInput size="md" label="상세주소" value={formatOptionalValue(detail.addressDetail)} readOnly state="view" />
|
|
| 218 |
+ <FoxInput size="md" label="상세주소" value={formatOptionalValue(merchant?.addressDetail)} readOnly state="view" />
|
|
| 178 | 219 |
</div> |
| 179 | 220 |
</div> |
| 180 | 221 |
|
... | ... | @@ -185,7 +226,7 @@ |
| 185 | 226 |
name="description" |
| 186 | 227 |
label="한줄 소개" |
| 187 | 228 |
placeholder="앱 목록·상세에 노출되는 한 줄 설명" |
| 188 |
- defaultValue={detail.description ?? ''}
|
|
| 229 |
+ defaultValue={detail?.description ?? ''}
|
|
| 189 | 230 |
maxLength={DESCRIPTION_MAX_LENGTH}
|
| 190 | 231 |
invalid={Boolean(errors.description)}
|
| 191 | 232 |
message={errors.description}
|
... | ... | @@ -197,7 +238,7 @@ |
| 197 | 238 |
name="openTime" |
| 198 | 239 |
type="time" |
| 199 | 240 |
label="영업 시작" |
| 200 |
- defaultValue={detail.openTime ?? ''}
|
|
| 241 |
+ defaultValue={detail?.openTime ?? ''}
|
|
| 201 | 242 |
invalid={Boolean(errors.openTime)}
|
| 202 | 243 |
message={errors.openTime}
|
| 203 | 244 |
/> |
... | ... | @@ -208,7 +249,7 @@ |
| 208 | 249 |
name="closeTime" |
| 209 | 250 |
type="time" |
| 210 | 251 |
label="영업 종료" |
| 211 |
- defaultValue={detail.closeTime ?? ''}
|
|
| 252 |
+ defaultValue={detail?.closeTime ?? ''}
|
|
| 212 | 253 |
invalid={Boolean(errors.closeTime)}
|
| 213 | 254 |
message={errors.closeTime}
|
| 214 | 255 |
/> |
... | ... | @@ -219,7 +260,7 @@ |
| 219 | 260 |
name="closedDays" |
| 220 | 261 |
label="휴무일" |
| 221 | 262 |
placeholder="예) 매주 월요일" |
| 222 |
- defaultValue={detail.closedDays ?? ''}
|
|
| 263 |
+ defaultValue={detail?.closedDays ?? ''}
|
|
| 223 | 264 |
maxLength={CLOSED_DAYS_MAX_LENGTH}
|
| 224 | 265 |
invalid={Boolean(errors.closedDays)}
|
| 225 | 266 |
message={errors.closedDays}
|
... | ... | @@ -254,7 +295,7 @@ |
| 254 | 295 |
max={SORT_ORDER_MAX}
|
| 255 | 296 |
label="노출 순서" |
| 256 | 297 |
placeholder="숫자 (낮을수록 상단)" |
| 257 |
- defaultValue={detail.sortOrder === null ? '' : String(detail.sortOrder)}
|
|
| 298 |
+ defaultValue={detail?.sortOrder == null ? '' : String(detail.sortOrder)}
|
|
| 258 | 299 |
invalid={Boolean(errors.sortOrder)}
|
| 259 | 300 |
message={errors.sortOrder}
|
| 260 | 301 |
/> |
... | ... | @@ -269,10 +310,10 @@ |
| 269 | 310 |
className={styles.section}
|
| 270 | 311 |
> |
| 271 | 312 |
<MerchantImageField |
| 272 |
- defaultThumbnailUrl={detail.thumbnailUrl}
|
|
| 273 |
- retainedThumbnailId={detail.thumbnailFileId}
|
|
| 274 |
- defaultImageUrls={detail.imageUrls}
|
|
| 275 |
- retainedImageFileId={detail.imageFileId}
|
|
| 313 |
+ defaultThumbnailUrl={detail?.thumbnailUrl ?? null}
|
|
| 314 |
+ retainedThumbnailId={detail?.thumbnailFileId ?? null}
|
|
| 315 |
+ defaultImageUrls={detail?.imageUrls ?? []}
|
|
| 316 |
+ retainedImageFileId={detail?.imageFileId ?? null}
|
|
| 276 | 317 |
thumbnailError={errors.thumbnail}
|
| 277 | 318 |
imagesError={errors.images}
|
| 278 | 319 |
/> |
... | ... | @@ -284,10 +325,10 @@ |
| 284 | 325 |
description="앱 상세 화면의 메뉴 목록에 노출된다" |
| 285 | 326 |
className={styles.section}
|
| 286 | 327 |
> |
| 287 |
- <MerchantProductTable frcsNo={detail.id} products={products} canAdd={isEdit} />
|
|
| 328 |
+ <MerchantProductTable frcsNo={frcsNo} products={products} canAdd={isEdit} />
|
|
| 288 | 329 |
</FoxCard> |
| 289 | 330 |
|
| 290 |
- {isEdit && (
|
|
| 331 |
+ {detail && (
|
|
| 291 | 332 |
<FoxCard size="lg" title="등록 정보" className={styles.section}>
|
| 292 | 333 |
<FoxDescriptionList |
| 293 | 334 |
layout="inline" |
... | ... | @@ -313,7 +354,7 @@ |
| 313 | 354 |
|
| 314 | 355 |
<FoxButtonPanel> |
| 315 | 356 |
<FoxButtonGroup size="lg"> |
| 316 |
- {isEdit && (
|
|
| 357 |
+ {detail && (
|
|
| 317 | 358 |
<> |
| 318 | 359 |
<FoxButton type="default" size="lg" label="삭제" disabled={isBusy} onAction={confirmDelete} />
|
| 319 | 360 |
<FoxButton |
--- app/(protected)/(basic)/system/merchant-details/[frcsNo]/page.tsx
+++ app/(protected)/(basic)/system/merchant-details/[frcsNo]/page.tsx
... | ... | @@ -1,19 +1,21 @@ |
| 1 | 1 |
import type { Metadata } from 'next';
|
| 2 |
-import { notFound } from 'next/navigation';
|
|
| 2 |
+import { notFound, redirect } from 'next/navigation';
|
|
| 3 | 3 |
import { verifySession } from '@/lib/auth/dal';
|
| 4 | 4 |
import { fetchCommonCodes } from '@/lib/data/repositories/common-code-repository';
|
| 5 | 5 |
import { fetchMerchantDetail } from '@/lib/data/repositories/merchant-detail-repository';
|
| 6 | 6 |
import { fetchMerchantProducts } from '@/lib/data/repositories/merchant-product-repository';
|
| 7 | 7 |
import { CODE_GROUP } from '@/lib/domain/common-code';
|
| 8 |
+import { merchantDetailNewPath } from '@/lib/domain/merchant-detail-query';
|
|
| 8 | 9 |
import { MerchantDetailForm } from './_components/merchant-detail-form';
|
| 9 | 10 |
|
| 10 |
-export const metadata: Metadata = { title: '가맹몰 상세 등록·수정' };
|
|
| 11 |
+export const metadata: Metadata = { title: '가맹몰 상세 수정' };
|
|
| 11 | 12 |
export const dynamic = 'force-dynamic'; |
| 12 | 13 |
|
| 13 | 14 |
interface PageProps {
|
| 14 | 15 |
params: Promise<{ frcsNo: string }>;
|
| 15 | 16 |
} |
| 16 | 17 |
|
| 18 |
+/** 수정 화면 — 상세가 있는 가맹점만. 아직 없는 가맹점이면 등록 화면으로 보내 거기서 고르게 한다. */ |
|
| 17 | 19 |
export default async function Page({ params }: PageProps) {
|
| 18 | 20 |
await verifySession(); |
| 19 | 21 |
|
... | ... | @@ -22,10 +24,12 @@ |
| 22 | 24 |
if (!detail) {
|
| 23 | 25 |
notFound(); |
| 24 | 26 |
} |
| 27 |
+ if (!detail.hasDetail) {
|
|
| 28 |
+ redirect(merchantDetailNewPath(frcsNo)); |
|
| 29 |
+ } |
|
| 25 | 30 |
|
| 26 |
- // 상세가 없으면 백엔드가 메뉴 조회를 빈 목록으로 답한다 — 따로 가릴 것 없다. |
|
| 27 | 31 |
const [products, categories] = await Promise.all([ |
| 28 |
- detail.hasDetail ? fetchMerchantProducts(frcsNo) : Promise.resolve([]), |
|
| 32 |
+ fetchMerchantProducts(frcsNo), |
|
| 29 | 33 |
fetchCommonCodes(CODE_GROUP.merchantType), |
| 30 | 34 |
]); |
| 31 | 35 |
|
--- app/(protected)/(basic)/system/merchant-details/_actions.ts
+++ app/(protected)/(basic)/system/merchant-details/_actions.ts
... | ... | @@ -222,7 +222,7 @@ |
| 222 | 222 |
const frcsNo = readString(formData, 'frcsNo'); |
| 223 | 223 |
const isEdit = readString(formData, 'mode') === 'edit'; |
| 224 | 224 |
if (!frcsNo) {
|
| 225 |
- return { status: 'error', message: INVALID_REQUEST_MESSAGE };
|
|
| 225 |
+ return { status: 'error', errors: { frcsNo: '업체를 선택해 주세요.' } };
|
|
| 226 | 226 |
} |
| 227 | 227 |
|
| 228 | 228 |
let failed: MerchantDetailFormState | null = null; |
--- app/(protected)/(basic)/system/merchant-details/_components/merchant-detail-list.tsx
+++ app/(protected)/(basic)/system/merchant-details/_components/merchant-detail-list.tsx
... | ... | @@ -26,6 +26,7 @@ |
| 26 | 26 |
import {
|
| 27 | 27 |
FILTER_ALL, |
| 28 | 28 |
MERCHANT_DETAILS_PATH, |
| 29 |
+ MERCHANT_DETAIL_NEW_PATH, |
|
| 29 | 30 |
MERCHANT_DETAIL_PAGE_SIZE_OPTIONS, |
| 30 | 31 |
buildMerchantDetailHref, |
| 31 | 32 |
clampDateRange, |
... | ... | @@ -55,9 +56,8 @@ |
| 55 | 56 |
/** |
| 56 | 57 |
* 가맹몰 상세 목록 — 기획 BO-MAL-001을 「관리자관리 > 가맹몰 상세 관리」로 옮긴 것. |
| 57 | 58 |
* |
| 58 |
- * 가맹점 전체가 오고 상세가 붙은 건만 상태·등록일이 있다. 버튼 구성은 시안 그대로다 — |
|
| 59 |
- * [+ 업체 등록]과 행의 [수정][비활성][삭제]를 모두 둔다(사용자 확정, 동작보다 시안 우선). |
|
| 60 |
- * 상세는 기존 가맹점에만 붙으므로 등록은 행의 [수정]으로 들어간다. |
|
| 59 |
+ * 상세가 등록된 가맹점만 선다(사용자 확정) — Repository가 가맹점 전체에서 걸러 준다. [+ 업체 등록]은 |
|
| 60 |
+ * 등록 화면으로 가서 상세가 없는 가맹점을 고르고, 행의 [수정]은 수정 화면으로 간다. |
|
| 61 | 61 |
* |
| 62 | 62 |
* 이슈: 메뉴 건수 열은 목록 응답에 없어 `-`다(보고함). 카테고리·상태도 백엔드가 아직 주지 |
| 63 | 63 |
* 않아 대부분 `-`로 보인다. |
... | ... | @@ -366,19 +366,12 @@ |
| 366 | 366 |
disabled={isBusy || selectedIds.size === 0}
|
| 367 | 367 |
onAction={confirmBulkDelete}
|
| 368 | 368 |
/> |
| 369 |
- {/* 시안 BO-MAL-001의 [+ 업체 등록]. 상세는 기존 가맹점에만 붙어 여기서 업체를 만들 수
|
|
| 370 |
- 없다 — 자리는 시안대로 두고 누르면 가는 곳을 안내한다(사용자 확정). */} |
|
| 371 | 369 |
<FoxButton |
| 372 | 370 |
type="primary" |
| 373 | 371 |
size="md" |
| 374 | 372 |
leadingIcon={<i className="fox-ico fox-ico-Plus" aria-hidden="true" />}
|
| 375 | 373 |
label="업체 등록" |
| 376 |
- onAction={() =>
|
|
| 377 |
- showToast({
|
|
| 378 |
- variant: 'info', |
|
| 379 |
- message: '업체(가맹점)는 가맹점 관리에서 등록합니다. 여기서는 등록된 가맹점의 상세를 관리합니다.', |
|
| 380 |
- }) |
|
| 381 |
- } |
|
| 374 |
+ onAction={() => router.push(MERCHANT_DETAIL_NEW_PATH)}
|
|
| 382 | 375 |
/> |
| 383 | 376 |
</> |
| 384 | 377 |
} |
--- app/(protected)/(basic)/system/merchant-details/_components/merchant-detail-row-actions.tsx
+++ app/(protected)/(basic)/system/merchant-details/_components/merchant-detail-row-actions.tsx
... | ... | @@ -17,9 +17,8 @@ |
| 17 | 17 |
} |
| 18 | 18 |
|
| 19 | 19 |
/** |
| 20 |
- * 기획 BO-MAL-001 관리 열 — 모든 행에 [수정] [비활성|노출] [삭제]. 상세가 없는 가맹점도 시안 |
|
| 21 |
- * 그대로 세 버튼을 둔다(사용자 확정 — 동작보다 시안 우선). [수정]은 등록 화면으로 이어지고, |
|
| 22 |
- * 나머지는 백엔드가 NOT_FOUND로 거절해 사유가 토스트로 올라온다. |
|
| 20 |
+ * 기획 BO-MAL-001 관리 열 — [수정] [비활성|노출] [삭제]. 목록에는 상세가 있는 가맹점만 서므로 |
|
| 21 |
+ * [수정]은 수정 화면으로 간다. |
|
| 23 | 22 |
*/ |
| 24 | 23 |
export function MerchantDetailRowActions({ row }: MerchantDetailRowActionsProps) {
|
| 25 | 24 |
const router = useRouter(); |
--- app/(protected)/(basic)/system/merchant-details/_components/merchant-product-table.tsx
+++ app/(protected)/(basic)/system/merchant-details/_components/merchant-product-table.tsx
... | ... | @@ -48,7 +48,7 @@ |
| 48 | 48 |
</div> |
| 49 | 49 |
{!canAdd && (
|
| 50 | 50 |
<p className={styles.hint}>
|
| 51 |
- 아래 [등록]으로 상세를 먼저 저장하면 이 화면에서 바로 메뉴를 추가할 수 있습니다. |
|
| 51 |
+ 아래 [등록]으로 상세를 먼저 저장하면 이어지는 수정 화면에서 메뉴를 추가할 수 있습니다. |
|
| 52 | 52 |
</p> |
| 53 | 53 |
)} |
| 54 | 54 |
|
+++ app/(protected)/(basic)/system/merchant-details/new/page.tsx
... | ... | @@ -0,0 +1,34 @@ |
| 1 | +import type { Metadata } from 'next'; | |
| 2 | +import { verifySession } from '@/lib/auth/dal'; | |
| 3 | +import { fetchCommonCodes } from '@/lib/data/repositories/common-code-repository'; | |
| 4 | +import { fetchMerchantDetailCandidates } from '@/lib/data/repositories/merchant-detail-repository'; | |
| 5 | +import { CODE_GROUP } from '@/lib/domain/common-code'; | |
| 6 | +import { MerchantDetailForm } from '../[frcsNo]/_components/merchant-detail-form'; | |
| 7 | + | |
| 8 | +export const metadata: Metadata = { title: '가맹몰 상세 등록' }; | |
| 9 | +export const dynamic = 'force-dynamic'; | |
| 10 | + | |
| 11 | +interface PageProps { | |
| 12 | + searchParams: Promise<Record<string, string | string[] | undefined>>; | |
| 13 | +} | |
| 14 | + | |
| 15 | +/** 등록 화면 — 상세가 없는 가맹점 중 하나를 골라 상세를 붙인다. `?frcsNo=`로 미리 고를 수 있다. */ | |
| 16 | +export default async function Page({ searchParams }: PageProps) { | |
| 17 | + await verifySession(); | |
| 18 | + | |
| 19 | + const params = await searchParams; | |
| 20 | + const requested = Array.isArray(params.frcsNo) ? params.frcsNo[0] : params.frcsNo; | |
| 21 | + const [candidates, categories] = await Promise.all([ | |
| 22 | + fetchMerchantDetailCandidates(), | |
| 23 | + fetchCommonCodes(CODE_GROUP.merchantType), | |
| 24 | + ]); | |
| 25 | + const initialFrcsNo = candidates.some((row) => row.id === requested) ? requested : undefined; | |
| 26 | + | |
| 27 | + return ( | |
| 28 | + <MerchantDetailForm | |
| 29 | + candidates={candidates} | |
| 30 | + initialFrcsNo={initialFrcsNo} | |
| 31 | + categories={categories} | |
| 32 | + /> | |
| 33 | + ); | |
| 34 | +} |
--- lib/data/repositories/merchant-detail-repository.ts
+++ lib/data/repositories/merchant-detail-repository.ts
... | ... | @@ -15,6 +15,7 @@ |
| 15 | 15 |
* |
| 16 | 16 |
* ``` |
| 17 | 17 |
* GET /api/v1/mngr/voc/detail/pagination TB_COM_VOUCHER ⟕ TB_COM_VOUCHER_DTL — 가맹점 전체 |
| 18 |
+ * (화면은 상세 있는 건만 목록에, 없는 건은 등록 선택지에) |
|
| 18 | 19 |
* GET /api/v1/mngr/voc/detail/{frcsNo}
|
| 19 | 20 |
* POST /api/v1/mngr/voc/detail @RequestBody · 가맹점이 있어야 붙는다 |
| 20 | 21 |
* PUT /api/v1/mngr/voc/detail/{frcsNo} @RequestBody
|
... | ... | @@ -146,21 +147,28 @@ |
| 146 | 147 |
}; |
| 147 | 148 |
} |
| 148 | 149 |
|
| 149 |
-export async function fetchMerchantDetails( |
|
| 150 |
- query: MerchantDetailQuery |
|
| 151 |
-): Promise<{ items: MerchantDetailSummary[]; totalCount: number }> {
|
|
| 150 |
+type SummaryFilters = Pick< |
|
| 151 |
+ MerchantDetailQuery, |
|
| 152 |
+ 'keyword' | 'category' | 'visibility' | 'startDate' | 'endDate' |
|
| 153 |
+>; |
|
| 154 |
+ |
|
| 155 |
+async function fetchSummaryPage( |
|
| 156 |
+ filters: Partial<SummaryFilters>, |
|
| 157 |
+ pageIndex: number, |
|
| 158 |
+ pageSize: number |
|
| 159 |
+): Promise<{ items: MerchantDetailSummary[]; rowCount: number; totalCount: number }> {
|
|
| 152 | 160 |
const accessToken = await getSessionAccessToken(); |
| 153 | 161 |
|
| 154 | 162 |
const result = await backendFetch<unknown>(`${DETAIL_PATH}/pagination`, {
|
| 155 | 163 |
method: 'GET', |
| 156 | 164 |
query: {
|
| 157 |
- ...(query.keyword ? { searchFrcsNm: query.keyword } : {}),
|
|
| 158 |
- ...(query.category ? { searchFrcsTypeCd: query.category } : {}),
|
|
| 159 |
- ...(query.visibility ? { searchUseYn: query.visibility } : {}),
|
|
| 160 |
- ...(query.startDate ? { searchStartDt: query.startDate } : {}),
|
|
| 161 |
- ...(query.endDate ? { searchEndDt: query.endDate } : {}),
|
|
| 162 |
- pageIndex: query.page, |
|
| 163 |
- recordCountPerPage: query.pageSize, |
|
| 165 |
+ ...(filters.keyword ? { searchFrcsNm: filters.keyword } : {}),
|
|
| 166 |
+ ...(filters.category ? { searchFrcsTypeCd: filters.category } : {}),
|
|
| 167 |
+ ...(filters.visibility ? { searchUseYn: filters.visibility } : {}),
|
|
| 168 |
+ ...(filters.startDate ? { searchStartDt: filters.startDate } : {}),
|
|
| 169 |
+ ...(filters.endDate ? { searchEndDt: filters.endDate } : {}),
|
|
| 170 |
+ pageIndex, |
|
| 171 |
+ recordCountPerPage: pageSize, |
|
| 164 | 172 |
}, |
| 165 | 173 |
accessToken: accessToken ?? undefined, |
| 166 | 174 |
cache: 'no-store', |
... | ... | @@ -173,7 +181,7 @@ |
| 173 | 181 |
|
| 174 | 182 |
const data = result.data; |
| 175 | 183 |
if (data === null || data === undefined) {
|
| 176 |
- return { items: [], totalCount: 0 };
|
|
| 184 |
+ return { items: [], rowCount: 0, totalCount: 0 };
|
|
| 177 | 185 |
} |
| 178 | 186 |
if (!isRecord(data) || !Array.isArray(data.list)) {
|
| 179 | 187 |
throw new Error('가맹몰 상세 목록 응답의 형식이 올바르지 않습니다.');
|
... | ... | @@ -181,11 +189,52 @@ |
| 181 | 189 |
|
| 182 | 190 |
return {
|
| 183 | 191 |
items: data.list.flatMap(toSummary), |
| 192 |
+ // 매핑에서 걸러진 행이 있어도 페이지가 끝났는지는 원본 행 수로 판단한다. |
|
| 193 |
+ rowCount: data.list.length, |
|
| 184 | 194 |
totalCount: |
| 185 | 195 |
typeof data.totalCount === 'number' ? data.totalCount : data.list.length, |
| 186 | 196 |
}; |
| 187 | 197 |
} |
| 188 | 198 |
|
| 199 |
+// 백엔드 목록에는 "상세가 있는 건만" 조건이 없다(보고함). 그래서 전 페이지를 받아 여기서 거른다 — |
|
| 200 |
+// 가맹점은 많아야 수백 건이라 한두 번의 요청이다. 상한을 넘으면 그 뒤는 잘린다. |
|
| 201 |
+// TODO(백엔드): 상세 유무 조건이 생기면 이 훑기를 없애고 페이지 하나만 받는다. |
|
| 202 |
+const SCAN_PAGE_SIZE = 200; |
|
| 203 |
+const MAX_SCAN_PAGES = 25; |
|
| 204 |
+ |
|
| 205 |
+async function fetchAllSummaries( |
|
| 206 |
+ filters: Partial<SummaryFilters> |
|
| 207 |
+): Promise<MerchantDetailSummary[]> {
|
|
| 208 |
+ const items: MerchantDetailSummary[] = []; |
|
| 209 |
+ let seen = 0; |
|
| 210 |
+ for (let pageIndex = 1; pageIndex <= MAX_SCAN_PAGES; pageIndex += 1) {
|
|
| 211 |
+ const page = await fetchSummaryPage(filters, pageIndex, SCAN_PAGE_SIZE); |
|
| 212 |
+ items.push(...page.items); |
|
| 213 |
+ seen += page.rowCount; |
|
| 214 |
+ if (page.rowCount < SCAN_PAGE_SIZE || seen >= page.totalCount) {
|
|
| 215 |
+ break; |
|
| 216 |
+ } |
|
| 217 |
+ } |
|
| 218 |
+ return items; |
|
| 219 |
+} |
|
| 220 |
+ |
|
| 221 |
+/** 목록 — 상세가 있는 가맹점만, 화면 쪽 페이지로 잘라 준다(사용자 확정). */ |
|
| 222 |
+export async function fetchMerchantDetails( |
|
| 223 |
+ query: MerchantDetailQuery |
|
| 224 |
+): Promise<{ items: MerchantDetailSummary[]; totalCount: number }> {
|
|
| 225 |
+ const registered = (await fetchAllSummaries(query)).filter((row) => row.hasDetail); |
|
| 226 |
+ const start = (query.page - 1) * query.pageSize; |
|
| 227 |
+ return {
|
|
| 228 |
+ items: registered.slice(start, start + query.pageSize), |
|
| 229 |
+ totalCount: registered.length, |
|
| 230 |
+ }; |
|
| 231 |
+} |
|
| 232 |
+ |
|
| 233 |
+/** 등록 화면의 업체 선택지 — 아직 상세가 없는 가맹점 전부. */ |
|
| 234 |
+export async function fetchMerchantDetailCandidates(): Promise<MerchantDetailSummary[]> {
|
|
| 235 |
+ return (await fetchAllSummaries({})).filter((row) => !row.hasDetail);
|
|
| 236 |
+} |
|
| 237 |
+ |
|
| 189 | 238 |
export async function fetchMerchantDetail( |
| 190 | 239 |
frcsNo: string |
| 191 | 240 |
): Promise<MerchantDetail | null> {
|
--- lib/domain/merchant-detail-form.ts
+++ lib/domain/merchant-detail-form.ts
... | ... | @@ -29,6 +29,7 @@ |
| 29 | 29 |
|
| 30 | 30 |
export type MerchantDetailFormErrors = Partial< |
| 31 | 31 |
Record< |
| 32 |
+ | 'frcsNo' |
|
| 32 | 33 |
| 'categoryCode' |
| 33 | 34 |
| 'description' |
| 34 | 35 |
| 'openTime' |
--- lib/domain/merchant-detail-query.ts
+++ lib/domain/merchant-detail-query.ts
... | ... | @@ -1,11 +1,19 @@ |
| 1 | 1 |
import { MERCHANT_DETAIL_VISIBILITY_OPTIONS } from '@/lib/domain/merchant-detail';
|
| 2 | 2 |
|
| 3 | 3 |
export const MERCHANT_DETAILS_PATH = '/system/merchant-details'; |
| 4 |
+export const MERCHANT_DETAIL_NEW_PATH = `${MERCHANT_DETAILS_PATH}/new`;
|
|
| 4 | 5 |
|
| 5 | 6 |
export function merchantDetailPath(frcsNo: string): string {
|
| 6 | 7 |
return `${MERCHANT_DETAILS_PATH}/${encodeURIComponent(frcsNo)}`;
|
| 7 | 8 |
} |
| 8 | 9 |
|
| 10 |
+/** 등록 화면. `frcsNo`를 주면 그 가맹점을 미리 골라 둔다. */ |
|
| 11 |
+export function merchantDetailNewPath(frcsNo?: string): string {
|
|
| 12 |
+ return frcsNo |
|
| 13 |
+ ? `${MERCHANT_DETAIL_NEW_PATH}?frcsNo=${encodeURIComponent(frcsNo)}`
|
|
| 14 |
+ : MERCHANT_DETAIL_NEW_PATH; |
|
| 15 |
+} |
|
| 16 |
+ |
|
| 9 | 17 |
export function merchantProductNewPath(frcsNo: string): string {
|
| 10 | 18 |
return `${merchantDetailPath(frcsNo)}/products/new`;
|
| 11 | 19 |
} |
--- lib/domain/merchant-detail.ts
+++ lib/domain/merchant-detail.ts
... | ... | @@ -7,7 +7,10 @@ |
| 7 | 7 |
* 가져오고, 상세 항목만 등록·수정한다(사용자 확정). |
| 8 | 8 |
*/ |
| 9 | 9 |
|
| 10 |
-/** 목록 한 행. 가맹점 전체가 오며 상세 미등록 건은 `hasDetail`이 false다. */ |
|
| 10 |
+/** |
|
| 11 |
+ * 가맹점 한 건 + 상세 유무. 백엔드 목록은 가맹점 전체를 주지만 화면의 목록에는 상세가 있는 |
|
| 12 |
+ * 건만 서고(사용자 확정), 상세가 없는 건은 등록 화면의 업체 선택지가 된다. |
|
| 13 |
+ */ |
|
| 11 | 14 |
export type MerchantDetailSummary = {
|
| 12 | 15 |
/** 백엔드 `frcsNo` — 가맹점 코드이자 상세의 키. */ |
| 13 | 16 |
id: string; |
... | ... | @@ -25,7 +28,7 @@ |
| 25 | 28 |
isVisible: boolean | null; |
| 26 | 29 |
/** 상세 등록일(`d.FRST_REG_DT`). 없으면 상세가 아직 없는 가맹점이다. */ |
| 27 | 30 |
registeredAt: string | null; |
| 28 |
- /** 상세 행이 있는지 — 일괄 비활성·삭제 대상인지, 메뉴를 추가할 수 있는지를 가른다. */ |
|
| 31 |
+ /** 상세 행이 있는지 — 목록에 서는지, 등록 화면의 선택지가 되는지를 가른다. */ |
|
| 29 | 32 |
hasDetail: boolean; |
| 30 | 33 |
}; |
| 31 | 34 |
|
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?