Skip to content

Commit

Permalink
[feat] EditProfile 부분 우선 수정!
Browse files Browse the repository at this point in the history
  • Loading branch information
KinDDoGGang committed Nov 15, 2023
1 parent caf6d6d commit 1272a62
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
2 changes: 0 additions & 2 deletions components/RoomCard/RoomCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ interface PhotoProps {
}

const UserInfo = ({ userInfo }: UserInfoProps) => {
const router = useRouter();
const age = formatAge(userInfo.birthDate);

const handleUserClick = () => {
/*
router.push(
Expand Down
27 changes: 19 additions & 8 deletions pages/userInfo/editProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ProfileCamera from '@/public/icons/profileCamera.svg';
import { Profile } from '@/public/types/user';
import { modifyProfile } from '@/api/userInfo';
import { UserInfoProps } from '@/context/UserInfoProvider.tsx';
import useModal from '@/hooks/useModal.ts';

interface ProfileProps {
_imageSrc: string;
Expand All @@ -25,6 +26,7 @@ interface ImageComponentClickProps {
export default function EditProfile({ _imageSrc, userInfo }: ProfileProps) {
const [imageSrc, setImageSrc] = useState(_imageSrc);
const subHeader = 'font-pretendard font-semibold text-[16px]';
const { closeModal } = useModal();
const {
register,
watch,
Expand All @@ -38,15 +40,23 @@ export default function EditProfile({ _imageSrc, userInfo }: ProfileProps) {

const [buttonState, setButtonState] = useState(capitalizeFirstLetter(userInfo?.gender || ''));

const formatMmDdYyyyToYyyyMmDd = (inputDate: string) => {
const formatDate = (inputDate: string, format: string) => {
const parts = inputDate.split('-');
if (parts.length === 3) {
const month = parts[0];
const day = parts[1];
const year = parts[2];
return `${year}-${month}-${day}`;
if (format === 'yyyymmdd') {
const month = parts[0];
const day = parts[1];
const year = parts[2];
return `${year}-${month}-${day}`;
}
if (format === 'mmddyyyy') {
const year = parts[0];
const month = parts[1];
const day = parts[2];
return `${month}-${day}-${year}`;
}
}
return null;
return '';
};

const onSubmit: SubmitHandler<FieldValues> = async (data) => {
Expand All @@ -56,9 +66,10 @@ export default function EditProfile({ _imageSrc, userInfo }: ProfileProps) {
profileData.profileId = userInfo.id || 0;
profileData.description = data?.describe || '';
profileData.gender = buttonState.toUpperCase();
profileData.birthDate = formatMmDdYyyyToYyyyMmDd(data.dateOfBirth) || profileData.birthDate;
profileData.birthDate = formatDate(data.dateOfBirth, 'yyyymmdd') || profileData.birthDate;
const result = await modifyProfile(profileData);
toast('Successfully saved');
closeModal();
} catch (error) {
console.error('[ERROR] EDIT PROFILE', error);
}
Expand Down Expand Up @@ -181,7 +192,7 @@ export default function EditProfile({ _imageSrc, userInfo }: ProfileProps) {
placeholder="MM-DD-YYYY"
type="text"
register={register('dateOfBirth')}
value={userInfo?.birthDate}
value={formatDate(userInfo?.birthDate || '', 'mmddyyyy')}
/>
</section>
<div className="mb-[12px] mt-[32px]">
Expand Down

0 comments on commit 1272a62

Please sign in to comment.