-
Notifications
You must be signed in to change notification settings - Fork 0
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 #130 from IT-Cotato/hotfix/COT-6_implement_edit_cs…
…_word Hotfix/cot 6 implement edit cs word
- Loading branch information
Showing
19 changed files
with
336 additions
and
134 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
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,61 @@ | ||
import fetcherWithParams from '@utils/fetcherWithParams'; | ||
import { CotatoAllEducationResponse } from 'cotato-openapi-clients'; | ||
|
||
import { useRef } from 'react'; | ||
import useSWR from 'swr'; | ||
|
||
// | ||
// | ||
// | ||
|
||
interface UseEducationParams { | ||
generationId: number; | ||
educationId?: string; | ||
} | ||
|
||
interface UseEducationReturn { | ||
targetEducation: CotatoAllEducationResponse | undefined; | ||
educations: CotatoAllEducationResponse[] | undefined; | ||
isEducationLoading: boolean; | ||
isEducationError: any; | ||
} | ||
|
||
// | ||
// | ||
// | ||
|
||
export function useEducation({ | ||
generationId, | ||
educationId, | ||
}: UseEducationParams): UseEducationReturn { | ||
const _return = useRef<UseEducationReturn>({} as UseEducationReturn); | ||
|
||
if (!generationId) { | ||
throw new Error('generationId is required'); | ||
} | ||
|
||
const { data, isLoading, error } = useSWR<CotatoAllEducationResponse[]>( | ||
'/v1/api/education', | ||
(url) => fetcherWithParams(url, { generationId }), | ||
{ | ||
revalidateOnFocus: false, | ||
revalidateOnReconnect: false, | ||
revalidateIfStale: false, | ||
}, | ||
); | ||
|
||
const targetEducation = educationId | ||
? data?.find((education) => education.educationId === Number(educationId)) | ||
: undefined; | ||
|
||
// | ||
// | ||
// | ||
|
||
_return.current.targetEducation = targetEducation; | ||
_return.current.educations = data; | ||
_return.current.isEducationLoading = isLoading; | ||
_return.current.isEducationError = error; | ||
|
||
return _return.current; | ||
} |
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,37 @@ | ||
import useUser from '@/hooks/useUser'; | ||
import React, { useEffect } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
// | ||
// | ||
// | ||
|
||
const CSGuard = ({ children }: { children: React.ReactNode }) => { | ||
const navigate = useNavigate(); | ||
|
||
const { user, isUserError, isUserLoading } = useUser(); | ||
|
||
// | ||
// | ||
// | ||
useEffect(() => { | ||
if (isUserLoading) { | ||
return; | ||
} | ||
|
||
if (isUserError || user?.role === 'GENERAL') { | ||
window.alert('코테이토 회원 전용 페이지입니다.'); | ||
navigate('/'); | ||
|
||
return; | ||
} | ||
}, [isUserError, isUserLoading, user]); | ||
|
||
// | ||
// | ||
// | ||
|
||
return <>{children}</>; | ||
}; | ||
|
||
export default CSGuard; |
Oops, something went wrong.