Merge branch 'iipbs/wr/dev' into iipbs/dm/dev
This commit is contained in:
@@ -4,7 +4,6 @@ import React, { useCallback, useEffect, useState } from "react";
|
||||
import type { ControllerRenderProps, UseFormReturn } from "react-hook-form";
|
||||
import { FormField } from "../form";
|
||||
import { FormUi } from "../form_ui";
|
||||
import { SelectBox } from "../select";
|
||||
import { SdmSearchForm } from "./sdmNameBox";
|
||||
import { SearchAddressModal } from "../search_address/SearchAddressModal";
|
||||
|
||||
@@ -80,6 +79,11 @@ type FieldComponent = (
|
||||
field: ControllerRenderProps<FormSchema, keyof FormSchema>,
|
||||
) => React.ReactElement;
|
||||
|
||||
const getReadonlyInputClassName = (isReadonly?: boolean) =>
|
||||
isReadonly
|
||||
? "!text-xl text-gray-600 bg-gray-100 cursor-default"
|
||||
: "!text-xl text-gray-600";
|
||||
|
||||
export function SdmRegForm({
|
||||
form,
|
||||
onCheckboxChange,
|
||||
@@ -92,11 +96,6 @@ export function SdmRegForm({
|
||||
readOnly,
|
||||
openNetwork,
|
||||
}: SdmRegFormProps) {
|
||||
const [sidoValue, setSidoValue] = useState<string>("");
|
||||
const [sigunValue, setSigunValue] = useState<string>("");
|
||||
const [filteredSigunData, setFilteredSigunData] = useState<SelectDataType[]>([
|
||||
{ text: "전체", val: "0" },
|
||||
]);
|
||||
const [isBznmTotNoDisabled, setIsBznmTotNoDisabled] = useState(true);
|
||||
const [orgBznmNo, setOrgBznmNo] = useState<string>("");
|
||||
const [updateCoNm, setUpdateNm] = useState<string>("");
|
||||
@@ -134,46 +133,12 @@ export function SdmRegForm({
|
||||
const initializeSigunData = useCallback(
|
||||
(sidoCd: string) => {
|
||||
if (sidoCd === "0") {
|
||||
setSigunValue("0");
|
||||
setFilteredSigunData([{ text: "전체", val: "0" }]);
|
||||
form.setValue("sggCd", "");
|
||||
} else {
|
||||
const newFilteredData = [
|
||||
{ text: "전체", val: "0" },
|
||||
...selectSigunData.filter(
|
||||
(item: SelectDataType) => item.val.substring(0, 2) === sidoCd,
|
||||
),
|
||||
];
|
||||
setSigunValue("0");
|
||||
setFilteredSigunData(newFilteredData);
|
||||
form.setValue("sggCd", "");
|
||||
}
|
||||
},
|
||||
[selectSigunData],
|
||||
);
|
||||
|
||||
const onSelectValue = useCallback(
|
||||
(
|
||||
val: string,
|
||||
type: string,
|
||||
field: ControllerRenderProps<FormSchema, keyof FormSchema> | undefined,
|
||||
) => {
|
||||
if (!updateList?.dmdInfoId)
|
||||
switch (type) {
|
||||
case "ctpvCd":
|
||||
initializeSigunData(val);
|
||||
setSidoValue(val);
|
||||
field?.onChange(val);
|
||||
form.setValue("dmdInfoId", "");
|
||||
form.setValue("bznmTotNo", "");
|
||||
break;
|
||||
case "sggCd":
|
||||
setSigunValue(val);
|
||||
field?.onChange(val);
|
||||
form.setValue("dmdInfoId", "");
|
||||
form.setValue("bznmTotNo", "");
|
||||
break;
|
||||
}
|
||||
},
|
||||
[initializeSigunData, form, updateList],
|
||||
[form],
|
||||
);
|
||||
|
||||
const handleCheckboxChange = useCallback(
|
||||
@@ -207,13 +172,11 @@ export function SdmRegForm({
|
||||
// 수요처 불러온 후 사업자번호를 바꿀경우를 대비함
|
||||
setOrgBznmNo(rtnCompData?.dmdInfoId);
|
||||
const sidoCd = rtnCompData?.ctpvCd.trim() || "";
|
||||
setSidoValue(sidoCd);
|
||||
form.setValue("ctpvCd", sidoCd);
|
||||
initializeSigunData(sidoCd);
|
||||
|
||||
setTimeout(() => {
|
||||
const sigunCd = rtnCompData?.sggCd.trim() || "";
|
||||
setSigunValue(sigunCd);
|
||||
form.setValue("sggCd", sigunCd);
|
||||
}, 100);
|
||||
|
||||
@@ -258,7 +221,6 @@ export function SdmRegForm({
|
||||
);
|
||||
if (!matchedSido) return;
|
||||
|
||||
setSidoValue(matchedSido.val);
|
||||
form.setValue("ctpvCd", matchedSido.val, { shouldValidate: true });
|
||||
initializeSigunData(matchedSido.val);
|
||||
|
||||
@@ -279,7 +241,6 @@ export function SdmRegForm({
|
||||
|
||||
if (!matchedSigun) return;
|
||||
|
||||
setSigunValue(matchedSigun.val);
|
||||
form.setValue("sggCd", matchedSigun.val, { shouldValidate: true });
|
||||
},
|
||||
[form, initializeSigunData, selectSidoData, selectSigunData],
|
||||
@@ -364,68 +325,6 @@ export function SdmRegForm({
|
||||
label: string;
|
||||
component: FieldComponent;
|
||||
}> = [
|
||||
{
|
||||
name: "ctpvCd",
|
||||
label: "시도",
|
||||
component: (field) =>
|
||||
updateList?.dmdInfoId ? (
|
||||
<Input
|
||||
placeholder="시도"
|
||||
type="text"
|
||||
className="!text-xl text-gray-600"
|
||||
onChange={(e) => {
|
||||
field.onChange(e.target.value);
|
||||
}}
|
||||
value={
|
||||
selectSidoData.find((item) => item.val === field.value?.trim())
|
||||
?.text ?? ""
|
||||
}
|
||||
readOnly={!!updateList?.dmdInfoId}
|
||||
/>
|
||||
) : (
|
||||
<SelectBox
|
||||
selectClass={undefined}
|
||||
label=""
|
||||
selectArray={selectSidoData}
|
||||
onSelectValue={(val) =>
|
||||
onSelectValue(val.toString(), "ctpvCd", field ?? "")
|
||||
}
|
||||
className=""
|
||||
value={sidoValue}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "sggCd",
|
||||
label: "시군구",
|
||||
component: (field) =>
|
||||
updateList?.dmdInfoId ? (
|
||||
<Input
|
||||
placeholder="시도"
|
||||
type="text"
|
||||
className="!text-xl text-gray-600"
|
||||
onChange={(e) => {
|
||||
field.onChange(e.target.value);
|
||||
}}
|
||||
value={
|
||||
selectSigunData.find((item) => item.val === field.value?.trim())
|
||||
?.text ?? ""
|
||||
}
|
||||
readOnly={!!updateList?.dmdInfoId}
|
||||
/>
|
||||
) : (
|
||||
<SelectBox
|
||||
selectClass={"!text-xl text-gray-600"}
|
||||
label=""
|
||||
selectArray={filteredSigunData}
|
||||
onSelectValue={(val) =>
|
||||
onSelectValue(val.toString(), "sggCd", field)
|
||||
}
|
||||
className=""
|
||||
value={sigunValue}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "dmdCoNm",
|
||||
label: "회사명",
|
||||
@@ -449,7 +348,7 @@ export function SdmRegForm({
|
||||
<Input
|
||||
placeholder="사업자등록번호를 입력하세요"
|
||||
type="text"
|
||||
className="!text-xl text-gray-600"
|
||||
className={getReadonlyInputClassName(!!updateList?.dmdInfoId)}
|
||||
onChange={(e) => bznNoChange(e, "dmdInfoId", field)}
|
||||
value={formatBusinessNumber(field.value ?? "")}
|
||||
readOnly={!!updateList?.dmdInfoId}
|
||||
@@ -468,7 +367,7 @@ export function SdmRegForm({
|
||||
<Input
|
||||
placeholder="여러사업장이 있을 경우 입력해주세요"
|
||||
type="text"
|
||||
className="!mt-5 !text-xl text-gray-600"
|
||||
className={`${getReadonlyInputClassName(!!updateList?.dmdInfoId)} !mt-5`}
|
||||
disabled={isBznmTotNoDisabled}
|
||||
onChange={(e) => bznNoChange(e, "bznmTotNo", field)}
|
||||
// {...field}
|
||||
@@ -488,7 +387,7 @@ export function SdmRegForm({
|
||||
{/* 우편번호 */}
|
||||
<Input
|
||||
type="text"
|
||||
className="!text-xl text-gray-600 w-64"
|
||||
className={`${getReadonlyInputClassName(true)} w-64`}
|
||||
readOnly={true}
|
||||
value={form.watch("zip") ?? ""}
|
||||
placeholder="우편번호"
|
||||
@@ -498,7 +397,7 @@ export function SdmRegForm({
|
||||
{/* 주소 */}
|
||||
<Input
|
||||
type="text"
|
||||
className="!text-xl text-gray-600"
|
||||
className={getReadonlyInputClassName(true)}
|
||||
readOnly={true}
|
||||
value={address ?? ""}
|
||||
placeholder="주소"
|
||||
@@ -507,7 +406,7 @@ export function SdmRegForm({
|
||||
<Input
|
||||
placeholder="상세 주소를 입력하세요"
|
||||
type="text"
|
||||
className="!text-xl text-gray-600"
|
||||
className={getReadonlyInputClassName(readOnly)}
|
||||
readOnly={readOnly}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
@@ -521,13 +420,51 @@ export function SdmRegForm({
|
||||
<Input
|
||||
placeholder="주소를 입력하세요"
|
||||
type="text"
|
||||
className="!text-xl text-gray-600"
|
||||
className={getReadonlyInputClassName(readOnly)}
|
||||
readOnly={readOnly}
|
||||
{...field}
|
||||
value={field.value ?? ""}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "ctpvCd",
|
||||
label: "시도",
|
||||
component: (field) => (
|
||||
<Input
|
||||
placeholder="시도"
|
||||
type="text"
|
||||
className={getReadonlyInputClassName(true)}
|
||||
onChange={(e) => {
|
||||
field.onChange(e.target.value);
|
||||
}}
|
||||
value={
|
||||
selectSidoData.find((item) => item.val === field.value?.trim())
|
||||
?.text ?? ""
|
||||
}
|
||||
readOnly={true}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "sggCd",
|
||||
label: "시군구",
|
||||
component: (field) => (
|
||||
<Input
|
||||
placeholder="시군구"
|
||||
type="text"
|
||||
className={getReadonlyInputClassName(true)}
|
||||
onChange={(e) => {
|
||||
field.onChange(e.target.value);
|
||||
}}
|
||||
value={
|
||||
selectSigunData.find((item) => item.val === field.value?.trim())
|
||||
?.text ?? ""
|
||||
}
|
||||
readOnly={true}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "telno",
|
||||
label: "전화번호",
|
||||
@@ -538,7 +475,7 @@ export function SdmRegForm({
|
||||
<Input
|
||||
placeholder="전화번호를 입력하세요"
|
||||
type="text"
|
||||
className="!text-xl text-gray-600"
|
||||
className={getReadonlyInputClassName(readOnly)}
|
||||
value={formattedValue}
|
||||
readOnly={readOnly}
|
||||
onChange={(e) => {
|
||||
@@ -557,7 +494,7 @@ export function SdmRegForm({
|
||||
<Input
|
||||
placeholder="패스워드를 입력하세요"
|
||||
type="password"
|
||||
className="!text-xl text-gray-600"
|
||||
className={getReadonlyInputClassName(readOnly)}
|
||||
readOnly={readOnly}
|
||||
{...field}
|
||||
value={field.value ?? ""}
|
||||
@@ -571,7 +508,7 @@ export function SdmRegForm({
|
||||
<Input
|
||||
placeholder="패스워드를 입력하세요"
|
||||
type="password"
|
||||
className="!text-xl text-gray-600"
|
||||
className={getReadonlyInputClassName(readOnly)}
|
||||
readOnly={readOnly}
|
||||
{...field}
|
||||
value={field.value ?? ""}
|
||||
@@ -595,8 +532,6 @@ export function SdmRegForm({
|
||||
const inputId = `${name}-input`;
|
||||
const errorId = `${name}-error`;
|
||||
const isRequired = [
|
||||
"ctpvCd",
|
||||
"sggCd",
|
||||
"dmdCoNm",
|
||||
"dmdInfoId",
|
||||
"daddr",
|
||||
|
||||
Reference in New Issue
Block a user