Skip to content

Commit

Permalink
Merge pull request #203 from SCBJ-7/feature/#188-refactor
Browse files Browse the repository at this point in the history
[#188] 입력필드 수정 시 체크박스 해제되도록 수정
  • Loading branch information
im-na0 authored Jan 25, 2024
2 parents 1011c94 + edac345 commit bad24f3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,28 @@ const UserInfoSection = () => {
register,
watch,
setValue,
resetField,
formState: { errors },
} = useFormContext();

const isDiffUser = watch("isDiffUser");

watch(["name", "email", "phone"]);

const userInfo = useLoadUserInfo(isDiffUser);

useEffect(() => {
if (isDiffUser && userInfo) {
setValue("name", userInfo.name, { shouldValidate: true });
setValue("email", userInfo.email, { shouldValidate: true });
setValue("phone", userInfo.phone, { shouldValidate: true });
} else if (!isDiffUser) {
resetField("name");
resetField("email");
resetField("phone");
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isDiffUser, setValue, userInfo]);

const handleFieldChange = () => {
setValue("isDiffUser", false);
};

return (
<S.HStack>
<S.Text variant="body2">이용자 정보</S.Text>
Expand Down Expand Up @@ -60,6 +61,7 @@ const UserInfoSection = () => {
type="text"
id="name"
placeholder="김양수"
onChange={handleFieldChange}
$isError={!!errors.name}
/>
{errors.name && (
Expand All @@ -83,6 +85,7 @@ const UserInfoSection = () => {
type="text"
id="email"
placeholder="이메일을 입력해주세요"
onChange={handleFieldChange}
$isError={!!errors.email}
/>
{errors.email && (
Expand All @@ -107,6 +110,7 @@ const UserInfoSection = () => {
type="text"
id="phone"
placeholder="전화번호를 입력해주세요"
onChange={handleFieldChange}
$isError={!!errors.phone}
/>
{errors.phone && (
Expand Down
1 change: 0 additions & 1 deletion src/pages/roomDetailPage/RoomDetail.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const OptionWrapper = styled(Flex)`
const Box = styled.div`
display: flex;
flex-direction: column;
align-items: center;
gap: 0.5rem;
background-color: ${({ theme }) => theme.color.greyScale7};
Expand Down

0 comments on commit bad24f3

Please sign in to comment.