+
{
);
};
-export default MRegisterForm;
+export default VMRegisterForm;
diff --git a/src/pages/register/VRadioGroup.tsx b/src/pages/register/VRadioGroup.tsx
new file mode 100644
index 00000000..a3102fb8
--- /dev/null
+++ b/src/pages/register/VRadioGroup.tsx
@@ -0,0 +1,151 @@
+import registerState, { RegisterType } from 'recoil/registerState';
+import { useRecoilState } from 'recoil';
+import DetailRadio from './DetailRadio';
+
+export function checkIfAllFilled(data: RegisterType) {
+ const allFieldsFilled = Object.values(data).every((value) => !!value);
+ return allFieldsFilled;
+}
+
+type RadioGroupProps = {
+ handleChange: (event: React.ChangeEvent) => void;
+ handleSexChange: (arg0: string) => void;
+ handleAdoptionStatusChange: (arg0: string) => void;
+ handleNeutralizationStatusChange: (arg0: string) => void;
+};
+
+const VRadioGroup = ({
+ handleChange,
+ handleSexChange,
+ handleAdoptionStatusChange,
+ handleNeutralizationStatusChange,
+}: RadioGroupProps) => {
+ const [petInfo, setPetInfo] = useRecoilState(registerState);
+
+ return (
+
+
+
์ฑ๋ณ
+
+ {
+ handleSexChange('MALE');
+ console.log(petInfo.sex);
+ setPetInfo((prev) => ({
+ ...prev,
+ isComplete: checkIfAllFilled(prev),
+ }));
+ }}
+ onChange={(e) => handleChange(e)}
+ />
+ {
+ handleSexChange('FEMALE');
+ console.log(petInfo.sex);
+ setPetInfo((prev) => ({
+ ...prev,
+ isComplete: checkIfAllFilled(prev),
+ }));
+ }}
+ onChange={(e) => handleChange(e)}
+ />
+
+
+
+
+
+ ์
์ ์ํ
+
+
+ {
+ handleAdoptionStatusChange('YES');
+ setPetInfo((prev) => ({
+ ...prev,
+ isComplete: checkIfAllFilled(prev),
+ }));
+ }}
+ onChange={(e) => handleChange(e)}
+ />
+ {
+ handleAdoptionStatusChange('NO');
+ setPetInfo((prev) => ({
+ ...prev,
+ isComplete: checkIfAllFilled(prev),
+ }));
+ }}
+ onChange={(e) => handleChange(e)}
+ />
+
+
+
+
+ ์ค์ฑํ ์ํ
+
+
+ {
+ handleNeutralizationStatusChange('YES');
+ setPetInfo((prev) => ({
+ ...prev,
+ isComplete: checkIfAllFilled(prev),
+ }));
+ }}
+ onChange={(e) => handleChange(e)}
+ />
+ {
+ handleNeutralizationStatusChange('NO');
+ setPetInfo((prev) => ({
+ ...prev,
+ isComplete: checkIfAllFilled(prev),
+ }));
+ }}
+ onChange={(e) => handleChange(e)}
+ />
+ {
+ handleNeutralizationStatusChange('UNKNOWN');
+ setPetInfo((prev) => ({
+ ...prev,
+ isComplete: checkIfAllFilled(prev),
+ }));
+ }}
+ onChange={(e) => handleChange(e)}
+ />
+
+
+
+ );
+};
+
+export default VRadioGroup;
diff --git a/src/pages/signUp/SignupInputForm.tsx b/src/pages/signUp/SignupInputForm.tsx
index 057a2fd8..b0846711 100644
--- a/src/pages/signUp/SignupInputForm.tsx
+++ b/src/pages/signUp/SignupInputForm.tsx
@@ -1,11 +1,45 @@
import React, { useState } from 'react';
+import { useNavigate } from 'react-router-dom';
import { useRecoilState } from 'recoil';
import { shelterSignupState } from 'recoil/shelterState';
import VSignupInputForm from './VSignupInputForm';
+export interface EmailConfirmProps {
+ isValid: boolean;
+ checked: boolean;
+}
+
+interface EmailValidProps {
+ validText: string;
+ inValidText: string;
+ emailConfirmObj: EmailConfirmProps;
+}
+
const SignupInputForm = () => {
const [shelterInfo, setShelterInfo] = useRecoilState(shelterSignupState);
- const [confirm, setConfirm] = useState(false);
+ // confirm state์ ๊ฒฝ์ฐ, ์ผ์นํ์ง ์์ ๋ false
+ // isValid: ์ค๋ณต๊ฒ์ฌ ํต๊ณผํ๋๊ฐ?
+ // checked: ์ด๋ฉ์ผ ์ค๋ณต ๊ฒ์ฌ๋ฅผ ํ๋๊ฐ?
+ const [emailConfirm, setEmailConfirm] = useState({
+ isValid: true,
+ checked: false,
+ });
+ const [passwordConfirm, setPasswordConfirm] = useState(true);
+ const { isValid, checked } = emailConfirm;
+ const [emailValidText, setEmailValidText] = useState('');
+ const [emailInValidText, setEmailInValidText] = useState('');
+
+ const navigate = useNavigate();
+
+ const getEmailValidText = ({
+ validText,
+ inValidText,
+ emailConfirmObj,
+ }: EmailValidProps) => {
+ setEmailValidText(validText);
+ setEmailInValidText(inValidText);
+ setEmailConfirm(emailConfirmObj);
+ };
const duplicateCheck = () => {
// shelterInfo.email
@@ -19,9 +53,39 @@ const SignupInputForm = () => {
}),
})
.then((res) => {
- res.json();
+ return res.json();
})
- .then((data) => console.log('Data', data));
+ .then((data) => {
+ if (!data.success) {
+ getEmailValidText({
+ validText: '',
+ inValidText: data.error.message,
+ emailConfirmObj: {
+ isValid: false,
+ checked: false,
+ },
+ });
+ } else if (!shelterInfo.email) {
+ getEmailValidText({
+ validText: '',
+ inValidText: '',
+ // ์ ๋ฃ์ผ๋ฉด ๋น์นธ์ผ๋ก ๊ณต๊ฐ ์ฐจ์งํด์ ์ด๋ ๊ฒ ์กฐ๊ฑด ๋ฃ์ด์ค
+ emailConfirmObj: {
+ isValid: false,
+ checked: true,
+ },
+ });
+ } else {
+ getEmailValidText({
+ validText: '์ฌ์ฉ ๊ฐ๋ฅํ ์ด๋ฉ์ผ์
๋๋ค.',
+ inValidText: '',
+ emailConfirmObj: {
+ isValid: true,
+ checked: true,
+ },
+ });
+ }
+ });
};
const handleChange = (event: React.ChangeEvent) => {
@@ -42,9 +106,9 @@ const SignupInputForm = () => {
// ๋น๋ฐ๋ฒํธ ์ผ์นํ์ง ์๋ ๊ฒฝ์ฐ, ํ์ํ๊ธฐ ์ํด ํด๋น ๋ถ๋ถ ๊ตฌํ
case 'password-confirm':
if (target.value !== shelterInfo.password) {
- setConfirm(true);
+ setPasswordConfirm(false);
} else {
- setConfirm(false);
+ setPasswordConfirm(true);
}
break;
default:
@@ -54,29 +118,38 @@ const SignupInputForm = () => {
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
- // ํ์๊ฐ์
์ ๋ณด ๋ณด๋ด๋ API ์ ์ฉํด์ผ ๋จ
- fetch(`${process.env.REACT_APP_URI}/account/shelter`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- ...shelterInfo,
- email: shelterInfo.email,
- password: shelterInfo.password,
- name: shelterInfo.name,
- contact: shelterInfo.contact,
- zonecode: shelterInfo.zonecode,
- address: shelterInfo.address,
- }),
- })
- .then((res) => {
- // const token = res.headers.get('Authorization');
- return res.json();
+ // ์ค๋ณต ํ์ธ์ด ๋์ง ์์์ ๋
+ if (!emailConfirm.checked) {
+ alert('์ด๋ฉ์ผ ์ค๋ณต์ ํ์ธํด์ฃผ์ธ์');
+ }
+ // ์ ๋๋ก ํ์ธ๋์์ ๋
+ if (emailConfirm.isValid && passwordConfirm) {
+ fetch(`${process.env.REACT_APP_URI}/account/shelter`, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({
+ ...shelterInfo,
+ email: shelterInfo.email,
+ password: shelterInfo.password,
+ name: shelterInfo.name,
+ contact: shelterInfo.contact,
+ zonecode: shelterInfo.zonecode,
+ address: shelterInfo.address,
+ }),
})
- .then((data) => {
- console.log(data);
- });
+ .then((res) => {
+ return res.json();
+ })
+ .then((data) => {
+ if (!data.success) {
+ alert(data.error.message); // ์ด ๋ถ๋ถ์ ์ฃผ์ ๋ฐ๋ ๊ฑฐ ๋๋ฌธ์ ๊ทธ๋ฅ ํ
์คํธ๋ง ๋ฃ๊ธฐ ์ ๋งคํจ
+ return;
+ }
+ navigate('/login');
+ });
+ }
};
const SignupInputFormProps = {
@@ -84,7 +157,11 @@ const SignupInputForm = () => {
handleChange,
handleSubmit,
duplicateCheck,
- confirm,
+ passwordConfirm,
+ isValid,
+ checked,
+ emailValidText,
+ emailInValidText,
};
return ;
diff --git a/src/pages/signUp/VSignupInputForm.tsx b/src/pages/signUp/VSignupInputForm.tsx
index 6ac51ad3..14eb83fa 100644
--- a/src/pages/signUp/VSignupInputForm.tsx
+++ b/src/pages/signUp/VSignupInputForm.tsx
@@ -2,19 +2,27 @@ import AddressInputGroup from 'pages/signUp/AddressInputGroup';
import InputGroup from 'commons/InputGroup';
import React from 'react';
-interface Props {
+interface VSignupInputProps {
handleChange: (event: React.ChangeEvent) => void;
handleSubmit: (e: React.FormEvent) => void;
duplicateCheck: () => void;
- confirm: boolean;
+ isValid: boolean;
+ checked: boolean;
+ passwordConfirm: boolean;
+ emailValidText: string;
+ emailInValidText: string;
}
const VSignupInputForm = ({
handleChange,
handleSubmit,
duplicateCheck,
- confirm,
-}: Props) => {
+ isValid,
+ checked,
+ passwordConfirm,
+ emailValidText,
+ emailInValidText,
+}: VSignupInputProps) => {
return (
+ {checked && isValid && (
+
{emailValidText}
+ )}
+ {!checked && !isValid && (
+
{emailInValidText}
+ )}
- {confirm && (
+ {!passwordConfirm && (
๋น๋ฐ๋ฒํธ๊ฐ ์ผ์นํ์ง ์์ต๋๋ค.
)}
}>
+
}>
+
+
+
+ >
+ );
+};
+
+export default UpdatePage;
diff --git a/src/pages/update/UpdateRegisterForm.tsx b/src/pages/update/UpdateRegisterForm.tsx
new file mode 100644
index 00000000..7e047328
--- /dev/null
+++ b/src/pages/update/UpdateRegisterForm.tsx
@@ -0,0 +1,50 @@
+import { useState } from 'react';
+import { useRecoilState } from 'recoil';
+import registerState, { RegisterType } from 'recoil/registerState';
+import VMRegisterForm from './VUpdateRegisterForm';
+
+interface PetProps {
+ petInfo: RegisterType;
+}
+
+const UpdateRegisterForm = ({ petInfo }: PetProps) => {
+ const [petInfoState, setPetInfo] = useRecoilState(registerState);
+
+ const handleChange = (event: React.SyntheticEvent) => {
+ const target = event.target as HTMLInputElement;
+ const fieldName = target.id;
+ const newValue = target.value;
+
+ const updatedPetInfo = {
+ ...petInfoState,
+ [fieldName]: newValue,
+ };
+
+ // ์ํ ์
๋ฐ์ดํธ
+ setPetInfo(updatedPetInfo);
+
+ // useState์ setํจ์๋ก petInfo๋ฅผ ์
๋ฐ์ดํธํด๋, handleChange๊ฐ ์คํ๋ ๋์ petInfo๋ ์
๋ฐ์ดํธ ์ ์ petInfo๋ฅผ ๊ฐ๋ฆฌํต๋๋ค.
+ // ๋ฐ๋ผ์ tempPetInfo๋ฅผ ๋ง๋ค์ด์ ์ต์ ์ petInfo๋ฅผ ์ฌ์ฉํ๋๋ก ํ์ต๋๋ค.
+ const tempPetInfo = { ...petInfo, [fieldName]: newValue };
+ const allFieldsFilled = Object.values(tempPetInfo).every((value, index) => {
+ // isComplete๋ petInfo์ ๋ชจ๋ ํ๋๊ฐ ์ฑ์์ ธ ์์ ๋ true
+ if (index === Object.values(petInfo).length - 1) {
+ return true;
+ }
+ return !!value;
+ });
+ if (allFieldsFilled) {
+ console.log('๊ฒ์ฌ', petInfo);
+ setPetInfo((prev) => ({ ...prev, isComplete: true }));
+ } else setPetInfo((prev) => ({ ...prev, isComplete: false }));
+ };
+
+ const MRegisterProps = {
+ handleChange,
+ petInfo,
+ };
+
+ return
;
+};
+
+export default UpdateRegisterForm;
diff --git a/src/pages/update/UpdateTemplate.tsx b/src/pages/update/UpdateTemplate.tsx
new file mode 100644
index 00000000..3baf83fc
--- /dev/null
+++ b/src/pages/update/UpdateTemplate.tsx
@@ -0,0 +1,80 @@
+import { useQuery } from '@tanstack/react-query';
+import { getCookie } from 'commons/cookie/cookie';
+import { useEffect, useState } from 'react';
+import { useParams } from 'react-router-dom';
+import { useRecoilState } from 'recoil';
+import registerState from 'recoil/registerState';
+import DayModalInput from 'pages/register/DayModalInput';
+import UpdateHeader from './UpdateHeader';
+import PatchStatusSelectGroup from './PatchStatusSelectGroup';
+import UpdateRegisterForm from './UpdateRegisterForm';
+
+const UpdateTemplate = () => {
+ const params = useParams();
+ const petId = params.id;
+ const cookie = getCookie('loginToken');
+ const [updateState, setUpdateState] = useRecoilState(registerState);
+ const [error, setError] = useState({
+ isError: false,
+ errorMessage: '',
+ });
+
+ // petInfo return
+ const getPetInfo = async () => {
+ const res = await fetch(
+ `${process.env.REACT_APP_URI}/pet/register-info/${petId}`,
+ {
+ method: 'GET',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': `Bearer ${cookie}`,
+ },
+ },
+ )
+ .then((response) => {
+ return response.json();
+ })
+ .then((apiData) => {
+ if (apiData.success === false) {
+ throw new Error(apiData.message);
+ }
+ return { ...apiData.response };
+ });
+ return res;
+ };
+
+ const { data, isLoading, isError } = useQuery({
+ queryKey: ['pet-update'],
+ queryFn: () => getPetInfo(),
+ onSuccess: (fetchedData) => {
+ const { profileImageUrl, profileShortFormUrl, ...rest } = fetchedData;
+ setUpdateState({ ...rest, isComplete: true });
+ },
+ suspense: true,
+ });
+
+ // ๋ฐ์ดํฐ ๋ค์ด์ค๋ ๊ฒ ํ์ธ ์ฉ๋
+ useEffect(() => {
+ if (!isLoading && data) {
+ console.log('status: ', updateState);
+ }
+ }, [updateState]);
+
+ if (isError) {
+ return
{error.errorMessage}
;
+ }
+
+ return (
+ <>
+
+
+
+
+ >
+ );
+};
+
+export default UpdateTemplate;
diff --git a/src/pages/update/VUpdateRegisterForm.tsx b/src/pages/update/VUpdateRegisterForm.tsx
new file mode 100644
index 00000000..ed4e41f6
--- /dev/null
+++ b/src/pages/update/VUpdateRegisterForm.tsx
@@ -0,0 +1,108 @@
+import RadioGroup from 'pages/register/RadioGroup';
+import SelectBox from 'commons/SelectBox';
+import { RegisterType } from 'recoil/registerState';
+import InputGroup from './UpdateInputGroup';
+
+type RegisterProps = {
+ handleChange: (event: React.ChangeEvent
) => void;
+ petInfo: RegisterType;
+};
+
+const VMRegisterForm = ({ handleChange, petInfo }: RegisterProps) => {
+ console.log('dk', petInfo);
+ console.log(petInfo.name);
+ return (
+
+
+
+
+ {
+ handleChange(e);
+ }}
+ value={petInfo.name}
+ />
+
+
+ {
+ handleChange(e);
+ }}
+ value={petInfo.age}
+ />
+
+
+
+
+
+
+
+ {
+ handleChange(e);
+ }}
+ value={petInfo.size}
+ />
+
+
+
+
+ {
+ handleChange(e);
+ }}
+ value={petInfo.weight}
+ />
+
+
+ {
+ handleChange(e);
+ }}
+ value={petInfo.vaccinationStatus}
+ />
+
+
+
+
+ {
+ handleChange(e);
+ }}
+ value={petInfo.description}
+ />
+
+
+
+ );
+};
+
+export default VMRegisterForm;
diff --git a/src/recoil/registerState.ts b/src/recoil/registerState.ts
index c7eb8aae..a7b26adb 100644
--- a/src/recoil/registerState.ts
+++ b/src/recoil/registerState.ts
@@ -12,7 +12,7 @@ export interface RegisterType {
neutralizationStatus: string; // YES | NO | UNKNOWN
protectionExpirationDate: string; // ๋ณดํธ๋ง๋ฃ์ผ null ๊ฐ๋ฅ 2023-10-25
description: string; // String
- polygonProfile: {
+ petPolygonProfileDto: {
// 1 ~ 5 ์ ์
intelligence: number; // "์๋ฆฌํจ ์ ์"
affinity: number; // "์นํ๋ ฅ ์ ์",
@@ -37,12 +37,12 @@ const registerState = atom({
neutralizationStatus: '',
protectionExpirationDate: '',
description: '',
- polygonProfile: {
- intelligence: 1,
- affinity: 1,
- athletic: 1,
- adaptability: 1,
- activeness: 1,
+ petPolygonProfileDto: {
+ intelligence: 3,
+ affinity: 3,
+ athletic: 3,
+ adaptability: 3,
+ activeness: 3,
},
isComplete: false,
},