Skip to content

Commit

Permalink
✨ 글 작성 에러핸들링
Browse files Browse the repository at this point in the history
  • Loading branch information
Youjiiin committed Jan 15, 2025
1 parent 3338fa3 commit 1dd18a0
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 31 deletions.
6 changes: 3 additions & 3 deletions public/images/arrow/next.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions public/images/arrow/prev.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 3 additions & 4 deletions src/components/Loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import { FadeLoader } from 'react-spinners';

const Loading = () => {
return (
<div className="h-full flex flex-col gap-3 items-center justify-center">
<h1>로딩 중..</h1>
<FadeLoader color="#4CAF50" />
</div>
<div className="h-full flex flex-col gap-3 items-center justify-center">
<FadeLoader color="#4CAF50" className="w-[20px] h-[20px]" />
</div>
);
};

Expand Down
18 changes: 11 additions & 7 deletions src/components/PostType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ interface props {
<PostType type={typeBuy} /> */
}
function PostType({ type }: props) {
let buttonValue: string = '';
if (type == 'sell') buttonValue = '팔아요';
else if (type == 'buy') buttonValue = '같이 사요';

return (
<p className="border h-fit bg-back2 text-sub border-transparent text-[12px] py-1 px-2 text-center rounded-[4px]">
{buttonValue}
</p>
<>
{type === 'sell' ? (
<p className="border h-fit text-back2 bg-sub border-transparent text-[12px] py-1 px-2 text-center rounded-[4px]">
팔아요
</p>
) : (
<p className="border h-fit bg-back2 text-sub border-transparent text-[12px] py-1 px-2 text-center rounded-[4px]">
같이 사요
</p>
)}
</>
);
}

Expand Down
14 changes: 2 additions & 12 deletions src/components/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
import { forwardRef, useState } from 'react';
import { Location } from '../constants/location';
interface SelectTypes {
meetingLocation: string;
setMeetingLocation: (arg0: string) => void;
}

const Select = forwardRef<HTMLDivElement, SelectTypes>(
({ meetingLocation, setMeetingLocation }: SelectTypes, ref) => {
const location: string[] = [
'전체지역',
'서울',
'경기',
'강원',
'충청',
'경상',
'전라',
'제주',
];

const [isVisible, setIsVisible] = useState<boolean>(false);

// 클릭 시 토글 나오게
Expand All @@ -31,7 +21,7 @@ const Select = forwardRef<HTMLDivElement, SelectTypes>(
};

// 리스트 생성
const list = location.map((item, index) => (
const list = Location.map((item, index) => (
<li
key={item}
className={`flex flex-col items-center text-main ${
Expand Down
1 change: 1 addition & 0 deletions src/components/Total.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ function Total({ data, onRefetch }: TotalProps) {
pauseOnHover={false}
theme="colored"
transition={Slide}
toastClassName="mx-4"
/>
</div>
);
Expand Down
10 changes: 10 additions & 0 deletions src/constants/location.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const Location = [
'전체지역',
'서울',
'경기',
'강원',
'충청',
'경상',
'전라',
'제주',
];
1 change: 1 addition & 0 deletions src/pages/login/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ const Login: React.FC = () => {
pauseOnHover={false}
theme="colored"
transition={Slide}
toastClassName="mx-4"
/>
</>
);
Expand Down
6 changes: 5 additions & 1 deletion src/pages/main/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ const Main = () => {
imageScr={products?.mainImages[0]?.path || ''}
/>
))}
{isLoading && <Loading />}
{isLoading && (
<div className='pt-3'>
<Loading />
</div>
)}
{/* 더보기 버튼 */}
{items.length < totalItems && ( // 모든 데이터를 불러온 경우 버튼 숨김
<button
Expand Down
1 change: 1 addition & 0 deletions src/pages/signUp/signUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ const SignUp: React.FC = () => {
pauseOnHover={false}
theme="colored"
transition={Slide}
toastClassName="mx-4"
/>
</>
);
Expand Down
7 changes: 6 additions & 1 deletion src/pages/write/write.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ interface FormData {
type: string; // 판매글 타입
};
}
interface AxiosErrorResponse {
errors: { msg: string }[];
}

const Write = () => {
const {
Expand Down Expand Up @@ -90,9 +93,10 @@ const Write = () => {
});
},
onError: (err) => {
const axiosError = err as AxiosError;
const axiosError = err as AxiosError<AxiosErrorResponse>;
if (axiosError.response) {
console.error('Error Response:', axiosError.response.data); // 서버에서 반환된 에러 메시지
toast.error(`${axiosError.response.data.errors[0].msg}`);
} else {
console.error('Unexpected Error:', err); // 기타 에러
}
Expand Down Expand Up @@ -174,6 +178,7 @@ const Write = () => {
pauseOnHover={false}
theme="colored"
transition={Slide}
toastClassName="mx-4"
/>
<div className="min-h-screen bg-back1 pt-14 pb-[100px]">
<Header>
Expand Down

0 comments on commit 1dd18a0

Please sign in to comment.