-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from YAPP-Github/feature/FE-081
- Loading branch information
Showing
43 changed files
with
504 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
import { userKeys, userAPI } from './user'; | ||
import { boardKeys, boardAPI } from './board'; | ||
import { writeAPI, writeKeys } from './write'; | ||
|
||
export const queryKeys = { | ||
user: userKeys, | ||
board: boardKeys, | ||
write: writeKeys, | ||
} as const; | ||
|
||
export const api = { | ||
user: userAPI, | ||
board: boardAPI, | ||
write: writeAPI, | ||
} as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export { default as useGetBoard } from './useGetBoard'; | ||
|
||
export { default as usePostBoard } from './usePostBoard'; | ||
|
||
export { default as usePatchBoard } from './usePatchBoard'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { writeKeys } from '@/api/write/queryKeys'; | ||
import { writeAPI } from '@/api/write/api'; | ||
import { useSuspenseQuery } from '@suspensive/react-query'; | ||
import { BoardData } from '@/app/write/types'; | ||
|
||
interface Props { | ||
boardId: number; | ||
onSuccess: (data: BoardData) => void; | ||
} | ||
|
||
const useGetBoard = ({ boardId, onSuccess }: Props) => { | ||
return useSuspenseQuery({ | ||
queryKey: writeKeys.board(boardId), | ||
queryFn: () => writeAPI.getBoardDetail(boardId), | ||
onSuccess: (data) => { | ||
onSuccess(data); | ||
}, | ||
}); | ||
}; | ||
|
||
export default useGetBoard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useQueryClient } from '@tanstack/react-query'; | ||
import { useMutation } from '@/hooks'; | ||
import { boardKeys } from '@/api/board'; | ||
import { writeAPI } from '@/api/write/api'; | ||
|
||
const usePatchBoard = (boardId: number) => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation(writeAPI.patchBoard, { | ||
onSuccess: () => { | ||
void queryClient.invalidateQueries(boardKeys.detail(boardId)); | ||
}, | ||
}); | ||
}; | ||
|
||
export default usePatchBoard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './hooks'; | ||
export * from './queryKeys'; | ||
export * from './api'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const writeKeys = { | ||
all: ['write'], | ||
board: (boardId: number) => [...writeKeys.all, 'detail', boardId] as const, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { notFound } from 'next/navigation'; | ||
import { InputLoading } from '../components'; | ||
import { Suspense } from 'react'; | ||
import BoardForm from '../components/Form/BoardForm'; | ||
|
||
const BoardEditPage = async ({ | ||
params: { id }, | ||
}: { | ||
params: { | ||
id: string; | ||
}; | ||
}) => { | ||
const boardId = Number(id); | ||
if (Number.isNaN(boardId)) notFound(); | ||
|
||
return ( | ||
<Suspense fallback={<InputLoading />}> | ||
<BoardForm /> | ||
</Suspense> | ||
); | ||
}; | ||
|
||
export default BoardEditPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use client'; | ||
|
||
import FirstStep from './FirstStep'; | ||
import SecondStep from './SecondStep'; | ||
import { wrapper } from '../../style.css'; | ||
import { useFunnel } from '@/hooks'; | ||
import { useProfile } from '@/api/hooks'; | ||
import { useParams, useRouter } from 'next/navigation'; | ||
import WriteTitle from '../WriteTitle/WriteTitle'; | ||
import useSetFormData from '../../hooks/useSetFormData'; | ||
import useFormStore from '../../store/useFormStore'; | ||
import { useEffect } from 'react'; | ||
|
||
export default function BoardForm() { | ||
const { data } = useProfile(); | ||
const router = useRouter(); | ||
|
||
const { id: boardId } = useParams() as { id: string }; | ||
useSetFormData(boardId); | ||
const { reset, setData } = useFormStore(); | ||
const [step, { prevStep, nextStep }] = useFunnel(['1', '2']); | ||
const preventClose = (e: BeforeUnloadEvent) => { | ||
e.preventDefault(); | ||
e.returnValue = ''; | ||
}; | ||
|
||
useEffect(() => { | ||
window.addEventListener('beforeunload', preventClose); | ||
return () => { | ||
reset(); | ||
window.removeEventListener('beforeunload', preventClose); | ||
}; | ||
}, []); | ||
|
||
if (!data) { | ||
router.push('/login'); | ||
} | ||
|
||
return ( | ||
<div className={wrapper}> | ||
<WriteTitle prevStep={prevStep} /> | ||
{step === '1' && <FirstStep setData={setData} nextStep={nextStep} />} | ||
{step === '2' && <SecondStep boardId={Number(boardId)} reset={reset} isPatch />} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.