Skip to content

Commit

Permalink
Merge branch 'hotfix' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
wildcatco committed Aug 9, 2023
2 parents 563ab15 + 8c5cbaa commit 92dcdf0
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 88 deletions.
1 change: 0 additions & 1 deletion src/apis/dto/auth/accept-terms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export interface AcceptTermsRequest {
userId: number;
privacyAcceptedStatus: number;
termsOfUseAcceptedStatus: number;
marketingAcceptedStatus: number;
}

export interface AcceptTermsResponse {
Expand Down
2 changes: 1 addition & 1 deletion src/apis/hooks/users/useEditProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function useEditProfile() {
},
onSuccess: () => {
queryClient.refetchQueries({
queryKey: ['user'],
queryKey: ['userType'],
});
queryClient.refetchQueries({
queryKey: ['posts'],
Expand Down
30 changes: 23 additions & 7 deletions src/apis/hooks/users/useUser.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,46 @@
import { useQuery } from '@tanstack/react-query';
import { useQuery, useQueryClient } from '@tanstack/react-query';

import { GetUserResponse } from '@/apis/dto/users/get-user';
import { GetUserTypeResponse } from '@/apis/dto/users/get-user-type';
import { axiosInstance } from '@/libs/axios';
import { User } from '@/types/user';
import { useEffect } from 'react';

export default function useUser(
{ enabled }: { enabled: boolean } = { enabled: true },
) {
const { data, error: userTypeError } = useQuery({
queryKey: ['user'],
const queryClient = useQueryClient();

const {
data,
error: userTypeError,
isSuccess,
} = useQuery({
queryKey: ['userType'],
queryFn: async () => {
const res = await axiosInstance.get<GetUserTypeResponse>('/user/type');
return res.data;
},
retry: false,
enabled,
refetchInterval: 60 * 1000,
});

const userId = data?.userId;

const {
data: userData,
isLoading,
error,
} = useQuery({
queryKey: ['user', data?.userId],
queryKey: ['user', userId],
queryFn: async () => {
const res = await axiosInstance.get<GetUserResponse>(
`/user/${data?.userId}`,
`/user/${userId || 'fuck'}`,
);
return res.data;
},
retry: 5,
enabled: !!data,
enabled: !!userId,
});

if (userTypeError) {
Expand Down Expand Up @@ -70,6 +78,14 @@ export default function useUser(
}
: null;

useEffect(() => {
if (isSuccess) {
queryClient.refetchQueries({
queryKey: ['user', data.userId],
});
}
}, [isSuccess]);

return {
user,
isLoading,
Expand Down
3 changes: 2 additions & 1 deletion src/components/ImageFullScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function ImageFullScreen({
}, []);

return (
<div className="absolute left-0 top-0 z-[100] h-[100dvh] w-full bg-text-title-900">
<div className="absolute left-0 top-0 z-[100] h-full w-full bg-text-title-900">
<div className="absolute top-[1rem] z-[100] flex w-full items-center justify-between px-[1.3rem]">
<DeleteIcon className="invisible" onClick={onClose} />
<span
Expand All @@ -48,6 +48,7 @@ export default function ImageFullScreen({
/>
</div>
<Carousel
className="absolute top-1/2 -translate-y-1/2"
showThumbs={false}
showIndicators={false}
selectedItem={initialIndex}
Expand Down
34 changes: 18 additions & 16 deletions src/components/post/PostForm/PostForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,24 @@ export default function PostForm({
<div className="text-text-subTitle-700 font-custom-subheading">
투표 항목
</div>
{formData.voteOptions.map((_, i) => (
<PostVoteInput
key={i}
id={`post-form-voteOptions${i}`}
image={
formData?.voteOptions ? formData.voteOptions[i].image : null
}
onChange={handlers.voteOptionChange(i)}
className="w-full"
onUploadImage={handlers.voteOptionImageUpload(i)}
onDeleteImage={handlers.voteOptionImageDelete(i)}
readOnly={mode === 'edit'}
hasError={showError && i === voteOptionErrorIndex}
defaultValue={formData.voteOptions[i].label}
/>
))}
{formData.voteOptions
.filter((option) => option.label !== null)
.map((_, i) => (
<PostVoteInput
key={i}
id={`post-form-voteOptions${i}`}
image={
formData?.voteOptions ? formData.voteOptions[i].image : null
}
onChange={handlers.voteOptionChange(i)}
className="w-full"
onUploadImage={handlers.voteOptionImageUpload(i)}
onDeleteImage={handlers.voteOptionImageDelete(i)}
readOnly={mode === 'edit'}
hasError={showError && i === voteOptionErrorIndex}
defaultValue={formData.voteOptions[i].label}
/>
))}
<EditButton
type="button"
disabled={
Expand Down
2 changes: 1 addition & 1 deletion src/components/post/PostUserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function PostUserProfile({
className="flex h-[2.5rem] w-[2.5rem] items-center justify-center rounded-full bg-[#f4f4f5] text-[#b0b2b8] font-system-body1"
style={{ fontWeight: 'bold' }}
>
{String(age)[0] + '0'}
{String(age).slice(0, -1) + '0'}
</span>
)}
<span className="font-system-body2">{nickname}</span>
Expand Down
2 changes: 1 addition & 1 deletion src/components/post/form/PostTitleInput/PostTitleInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default function PostTitleInput({
/>
<div className="absolute right-0 top-1/2 flex -translate-y-1/2 items-center space-x-[0.8rem]">
{showReset && (
<button onClick={handleReset}>
<button onClick={handleReset} tabIndex={-1}>
<DeleteIcon
className="h-[1.6rem] w-[1.6rem] cursor-pointer rounded-full bg-background-button-300"
color="white"
Expand Down
6 changes: 3 additions & 3 deletions src/components/post/form/PostVoteInput/PostVoteInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function PostVoteInput({
className={twMerge(
'group relative w-[34rem] rounded-[0.5rem]',
className,
readOnly && 'pointer-events-none bg-background-voteBg-100'
readOnly && 'pointer-events-none bg-background-voteBg-100',
)}
>
<div className="relative">
Expand All @@ -90,12 +90,12 @@ export default function PostVoteInput({
'w-full rounded-[0.5rem] border border-background-dividerLine-300 bg-transparent py-[1.2rem] pl-[1.3rem] font-system-body4 placeholder:text-text-subExplain-400 placeholder:font-system-body3 group-focus-within:border-text-subTitle-700',
hasError &&
'border-semantic-warn-500 group-focus-within:border-semantic-warn-500',
readOnly && 'text-text-explain-500'
readOnly && 'text-text-explain-500',
)}
/>
<div className="absolute right-[1.2rem] top-1/2 flex -translate-y-1/2 space-x-[0.8rem]">
{showReset && (
<button onFocus={() => setShowReset(true)}>
<button tabIndex={-1} onFocus={() => setShowReset(true)}>
<DeleteIcon
className="h-[1.6rem] w-[1.6rem] cursor-pointer rounded-full bg-background-button-300"
color="white"
Expand Down
6 changes: 3 additions & 3 deletions src/components/register/form/BirthdayInput/BirthdayInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function BirthdayInput({
year: '',
month: '',
day: '',
}
},
);
const yearRef = useRef<HTMLInputElement>(null);
const monthRef = useRef<HTMLInputElement>(null);
Expand All @@ -53,7 +53,7 @@ export default function BirthdayInput({
setBirthday(newBirthday);
onChange(newBirthday);
setShowReset(
Boolean(newBirthday.year || newBirthday.month || newBirthday.day)
Boolean(newBirthday.year || newBirthday.month || newBirthday.day),
);

if (e.target.name === 'year' && e.target.value.length === 4) {
Expand Down Expand Up @@ -160,7 +160,7 @@ export default function BirthdayInput({
</div>
<div className="absolute right-0 top-1/2 flex -translate-y-1/2 items-center space-x-[0.5rem]">
{showReset && (
<button onClick={handleReset}>
<button onClick={handleReset} tabIndex={-1}>
<DeleteIcon
className="h-[1.6rem] w-[1.6rem] cursor-pointer rounded-full bg-background-button-300"
color="white"
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/inputs/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ export default function TextInput({
/>
<div className="absolute right-0 top-1/2 flex -translate-y-1/2 items-center space-x-[0.5rem]">
{showReset && (
<button onClick={handleReset}>
<button onClick={handleReset} tabIndex={-1}>
<DeleteIcon
className={twMerge(
'h-[1.6rem] w-[1.6rem] cursor-pointer rounded-full bg-background-button-300',
!successMessage && !errorMessage && 'mr-[1.3rem]'
!successMessage && !errorMessage && 'mr-[1.3rem]',
)}
color="white"
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/user/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function UserProfile() {
/>
) : (
<span className="flex h-[3.6rem] w-[3.6rem] items-center justify-center rounded-full bg-[#f4f4f5] text-[#b0b2b8] font-system-heading2">
{String(age)[0] + '0'}
{String(age).slice(0, -1) + '0'}
</span>
)}
<span className="text-[#2a2d37] font-custom-heading1">
Expand Down
1 change: 0 additions & 1 deletion src/pages/collect-information/CollectInformationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ function CollectInformationPage() {
userId: user.id,
termsOfUseAcceptedStatus: Number(accept.gochamTerm),
privacyAcceptedStatus: Number(accept.personalInformation),
marketingAcceptedStatus: Number(accept.marketing),
});
await editProfile({
userId: user.id,
Expand Down
43 changes: 4 additions & 39 deletions src/pages/register/RegisterTermPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ function RegisterTermPage() {
const [registerData, setRegisterData] = useAtom(registerDataAtom);
const { accept } = registerData;

const nextEnabled =
accept.gochamTerm && accept.personalInformation && accept.olderThan14;
const nextEnabled = accept.gochamTerm && accept.personalInformation;

const handleNext = () => {
navigate('/collect-information');
Expand All @@ -37,20 +36,13 @@ function RegisterTermPage() {
<section className="mt-[3.5rem]">
<TermCheckbox
text="모두 동의합니다."
checked={
accept.gochamTerm &&
accept.personalInformation &&
accept.olderThan14 &&
accept.marketing
}
checked={accept.gochamTerm && accept.personalInformation}
onCheck={(checked) =>
setRegisterData({
...registerData,
accept: {
gochamTerm: checked,
personalInformation: checked,
olderThan14: checked,
marketing: checked,
allCheck: checked,
},
})
Expand All @@ -60,7 +52,7 @@ function RegisterTermPage() {
<div className="space-y-[1.3rem]">
<TermCheckbox
text="[필수] 고민의 참견 이용약관 동의"
link="https://sharechang.notion.site/ac3f06fe803b497681f807f3df65fbe2"
link="https://sharechang.notion.site/2ad95f818e6a4df29afa5ecdf87e4052?pvs=4"
checked={accept.gochamTerm}
onCheck={(checked) => {
setRegisterData({
Expand All @@ -74,7 +66,7 @@ function RegisterTermPage() {
/>
<TermCheckbox
text="[필수] 개인정보 수집 및 이용 동의"
link="https://sharechang.notion.site/c18f70f5ee40492fb8cdb89336014097"
link="https://sharechang.notion.site/47d2c9861a704ef0aadf743856c97335?pvs=4"
checked={accept.personalInformation}
onCheck={(checked) => {
setRegisterData({
Expand All @@ -86,33 +78,6 @@ function RegisterTermPage() {
});
}}
/>
<TermCheckbox
text="[필수] 만 14세 이상 입니다."
checked={accept.olderThan14}
onCheck={(checked) => {
setRegisterData({
...registerData,
accept: {
...registerData.accept,
olderThan14: checked,
},
});
}}
/>
<TermCheckbox
text="[선택] 마케팅 목적 이용 동의"
link="https://sharechang.notion.site/c18f70f5ee40492fb8cdb89336014097"
checked={accept.marketing}
onCheck={(checked) => {
setRegisterData({
...registerData,
accept: {
...registerData.accept,
marketing: checked,
},
});
}}
/>
</div>
</section>
</div>
Expand Down
4 changes: 0 additions & 4 deletions src/states/registerData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ interface RegisterData {
accept: {
gochamTerm: boolean;
personalInformation: boolean;
olderThan14: boolean;
marketing: boolean;
allCheck: boolean;
};
}
Expand All @@ -28,8 +26,6 @@ export const registerDataAtom = atom<RegisterData>({
accept: {
gochamTerm: false,
personalInformation: false,
olderThan14: false,
marketing: false,
allCheck: false,
},
});
15 changes: 8 additions & 7 deletions src/utils/validations/postForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,25 @@ export function validatePostForm(
if (typeof deadline !== 'number') {
errorMessage.deadline = '투표 마감 시간을 선택해주세요.';
}
for (let i = 0; i < voteOptions.length; i++) {
const option = voteOptions[i];
const options = voteOptions.filter((option) => option.label);
for (let i = 0; i < options.length; i++) {
const option = options[i];
if (!option.label.trim() || (option.image && !option.label.trim())) {
errorMessage.voteOptions = '투표 항목은 텍스트를 포함해야 합니다.';
voteOptionErrorIndex = i;
return [errorMessage, voteOptionErrorIndex];
}
}
let count = 0;
for (const option of voteOptions) {
for (const option of options) {
if (option.label.trim()) {
count += 1;
}
}
if (count < 2) {
errorMessage.voteOptions = '투표 항목을 2개 이상 입력해주세요.';
for (let i = 0; i < voteOptions.length; i++) {
const option = voteOptions[i];
for (let i = 0; i < options.length; i++) {
const option = options[i];
if (!option.label) {
voteOptionErrorIndex = i;
break;
Expand All @@ -48,8 +49,8 @@ export function validatePostForm(
}

const labels: string[] = [];
for (let i = 0; i < voteOptions.length; i++) {
const option = voteOptions[i];
for (let i = 0; i < options.length; i++) {
const option = options[i];
if (labels.includes(option.label)) {
errorMessage.voteOptions =
'동일한 투표 항목을 중복으로 작성하실 수 없습니다.';
Expand Down

0 comments on commit 92dcdf0

Please sign in to comment.