-
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 #61 from sos-sejong-opensource-software/feat-admin…
…-faq feat: 관리자페이지 - FAQ 목록 조회, 생성, 삭제, 수정
- Loading branch information
Showing
21 changed files
with
399 additions
and
12 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
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,32 @@ | ||
import { Heading } from '@/components'; | ||
import { PAGE } from '@/constants'; | ||
import { useParams } from 'react-router-dom'; | ||
import { AdminCreateEditForm } from './components'; | ||
import { useAdminFaqQuery, useEditFaqMutation } from './hooks/query'; | ||
|
||
export function AdminEditFaq() { | ||
const { id: faqId } = useParams() as { id: string }; | ||
const { mutate: editFaq } = useEditFaqMutation(); | ||
|
||
const onFaqMutate = (data: CreateEditFaqRequest) => { | ||
editFaq({ faqId, payload: data }); | ||
}; | ||
|
||
const { data: queryData } = useAdminFaqQuery(faqId); | ||
|
||
const { question, answer, ...res } = queryData; | ||
const data = { | ||
title: question, | ||
context: answer, | ||
...res, | ||
}; | ||
|
||
return ( | ||
<div className="container"> | ||
<Heading as="h3" className="pageTitle"> | ||
{PAGE.EDIT_FAQ} | ||
</Heading> | ||
<AdminCreateEditForm mode="faq" data={data} onFaqMutate={onFaqMutate} /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Button, Heading, Table } from '@/components'; | ||
import { PAGE, PATH } from '@/constants/paths'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { useAdminFaqsTable } from './hooks'; | ||
|
||
export function AdminFaqList() { | ||
const navigate = useNavigate(); | ||
const { column, data } = useAdminFaqsTable(); | ||
|
||
return ( | ||
<> | ||
<div className="flex flex-row justify-between"> | ||
<Heading as="h3" className="pageTitle"> | ||
{PAGE.ALL_FAQS} | ||
<Button onClick={() => navigate(`${PATH.ADMIN}/${PATH.ADMIN_FAQS}/new`)}>글쓰기</Button> | ||
</Heading> | ||
</div> | ||
<Table column={column} data={data} /> | ||
</> | ||
); | ||
} |
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,21 @@ | ||
import { Heading } from '@/components'; | ||
import { PAGE } from '@/constants'; | ||
import { AdminCreateEditForm } from './components'; | ||
import { useCreateFaqMutation } from './hooks/query'; | ||
|
||
export function AdminNewFaq() { | ||
const { mutate: createFaq } = useCreateFaqMutation(); | ||
|
||
const onFaqMutate = (data: CreateEditFaqRequest) => { | ||
createFaq(data); | ||
}; | ||
|
||
return ( | ||
<div className="container"> | ||
<Heading as="h3" className="pageTitle"> | ||
{PAGE.NEW_FAQ} | ||
</Heading> | ||
<AdminCreateEditForm mode="faq" onFaqMutate={onFaqMutate} /> | ||
</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
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,22 @@ | ||
import { UseQueryOptions } from 'react-query'; | ||
import { AxiosError } from 'axios'; | ||
|
||
import { QUERY_KEYS } from '@/constants'; | ||
import { useSuspenseQuery } from '@/hooks/useSuspenseQuery'; | ||
|
||
import { getFaqs } from '../../api'; | ||
|
||
export const useAdminFaqListQuery = ( | ||
options?: UseQueryOptions<AdminFaqListResponse, AxiosError, AdminFaqListResponse, string> | ||
) => { | ||
return useSuspenseQuery( | ||
QUERY_KEYS.ADMIN_ALL_FAQS, | ||
async () => { | ||
const { data } = await getFaqs(); | ||
return data; | ||
}, | ||
{ | ||
...options, | ||
} | ||
); | ||
}; |
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 { UseQueryOptions } from 'react-query'; | ||
import { AxiosError } from 'axios'; | ||
|
||
import { QUERY_KEYS } from '@/constants'; | ||
import { useSuspenseQuery } from '@/hooks/useSuspenseQuery'; | ||
|
||
import { getFaqById } from '../../api'; | ||
|
||
export const useAdminFaqQuery = ( | ||
faqId: string, | ||
options?: UseQueryOptions<AdminFaqResponse, AxiosError, AdminFaqResponse, [string, string]> | ||
) => { | ||
return useSuspenseQuery( | ||
[QUERY_KEYS.ADMIN_FAQ, faqId], | ||
async ({ queryKey: [, faqId] }) => { | ||
const { data } = await getFaqById(faqId); | ||
return data; | ||
}, | ||
{ | ||
...options, | ||
} | ||
); | ||
}; |
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,19 @@ | ||
import { PATH } from '@/constants'; | ||
import { AxiosError, AxiosResponse } from 'axios'; | ||
import { useMutation, UseMutationOptions } from 'react-query'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { createFaq } from '../../api'; | ||
|
||
export const useCreateFaqMutation = ( | ||
options?: UseMutationOptions<AxiosResponse, AxiosError, CreateEditFaqRequest> | ||
) => { | ||
const navigate = useNavigate(); | ||
|
||
return useMutation((payload) => createFaq(payload), { | ||
...options, | ||
onSuccess: () => { | ||
alert('생성되었습니다.'); | ||
navigate(`${PATH.ADMIN}/${PATH.ADMIN_FAQS}`); | ||
}, | ||
}); | ||
}; |
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,14 @@ | ||
import { AxiosError, AxiosResponse } from 'axios'; | ||
import { useMutation, UseMutationOptions } from 'react-query'; | ||
import { deleteFaq } from '../../api'; | ||
|
||
export const useDeleteFaqMutation = ( | ||
options?: UseMutationOptions<AxiosResponse, AxiosError, string> | ||
) => { | ||
return useMutation((faqId) => deleteFaq(faqId), { | ||
...options, | ||
onSuccess: () => { | ||
alert('삭제되었습니다.'); | ||
}, | ||
}); | ||
}; |
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,26 @@ | ||
import { PATH, QUERY_KEYS } from '@/constants'; | ||
import { AxiosError, AxiosResponse } from 'axios'; | ||
import { useMutation, UseMutationOptions, useQueryClient } from 'react-query'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { editFaq } from '../../api'; | ||
|
||
type useEditFaqMutationProps = { | ||
faqId: string; | ||
payload: CreateEditFaqRequest; | ||
}; | ||
|
||
export const useEditFaqMutation = ( | ||
options?: UseMutationOptions<AxiosResponse, AxiosError, useEditFaqMutationProps> | ||
) => { | ||
const navigate = useNavigate(); | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation(({ faqId, payload }) => editFaq(faqId, payload), { | ||
...options, | ||
onSuccess: async () => { | ||
await queryClient.invalidateQueries(QUERY_KEYS.ADMIN_FAQ); | ||
alert('수정되었습니다.'); | ||
navigate(`${PATH.ADMIN}/${PATH.ADMIN_FAQS}`); | ||
}, | ||
}); | ||
}; |
Oops, something went wrong.