Skip to content

Commit

Permalink
데이터 관련 이것저것 (#105)
Browse files Browse the repository at this point in the history
* feat: 행사 detail 페이지일 경우 파일 list에 img만 있음

* style: 행사 content 이미지 styling

* refactor: 회의록, 학칙 api 연결 (머지하다 실수로 삭제했나봄)

* feat: pdf viewer - pdf url data resopnse로 수정

* feat:api 에러 시 404페이지로 리다이렉션

* fix: 에러처리 수정
  • Loading branch information
xxxjinn authored Aug 18, 2024
1 parent 0b0906c commit dcc697a
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 12 deletions.
38 changes: 37 additions & 1 deletion src/features/content/api/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ import {
GetNoticeDetailResData,
GetEventDetailResData,
GetTransactionDetailResData,
GetRuleDetailResData,
GetProceedingDetailResData,
} from './types';
import { EVENT_DETAIL_API, NOTICE_DETAIL_API, TRANSACTION_DETAIL_API } from '.';
import {
EVENT_DETAIL_API,
NOTICE_DETAIL_API,
PROCEEDING_DETAIL_API,
RULE_DETAIL_API,
TRANSACTION_DETAIL_API,
} from '.';

//학교 공지 detail
export const useGetCampusNoticeDetail = (
Expand Down Expand Up @@ -68,3 +76,31 @@ export const useGetTransactionDetail = (
...options,
});
};

export const useGetProceedingDetail = (
proceedingId: number,
options?: UseQueryOptions<GetProceedingDetailResData, AxiosError>,
) => {
return useQuery({
queryKey: ['proceedingDetail', proceedingId],
queryFn: async () => {
const data = await PROCEEDING_DETAIL_API.proceedingDetail(proceedingId);
return data;
},
...options,
});
};

export const useGetRuleDetail = (
ruleId: number,
options?: UseQueryOptions<GetRuleDetailResData, AxiosError>,
) => {
return useQuery({
queryKey: ['ruleDetail', ruleId],
queryFn: async () => {
const data = await RULE_DETAIL_API.ruleDetail(ruleId);
return data;
},
...options,
});
};
9 changes: 2 additions & 7 deletions src/features/content/model/usePdfDetail.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useGetRuleDetail, useGetProceedingDetail } from '../api/queries';

const usePdfDetail = () => {
//회칙/학칙 detail
const returnRuleDetailItem = (organization: string, id: number) => {
Expand Down Expand Up @@ -49,10 +51,3 @@ const usePdfDetail = () => {
};

export default usePdfDetail;
function useGetRuleDetail(id: number): { data: any; isSuccess: any } {
throw new Error('Function not implemented.');
}

function useGetProceedingDetail(id: number): { data: any; isSuccess: any } {
throw new Error('Function not implemented.');
}
20 changes: 18 additions & 2 deletions src/features/content/ui/CommonDetailComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import DateText from '@/widgets/DateText';
import Title from '@/widgets/Title';
import { formatDate } from '@/shared/lib/utils';
Expand All @@ -6,12 +8,18 @@ import ReactMarkdown from 'react-markdown';
import rehypeRaw from 'rehype-raw';
import { TbDownload } from 'react-icons/tb';
import { CommonDetailItem } from '../api/types';
import { usePathname } from 'next/navigation';

const CommonDetailComponent = ({
content: data,
}: {
content: CommonDetailItem | undefined;
}) => {
const pathname = usePathname();
const isEventDetailPage = pathname.includes('event');

const arr = [1, 2, 3, 4, 5, 6, 2];

if (data) {
return (
<div className="flex flex-col space-y-3">
Expand All @@ -29,13 +37,21 @@ const CommonDetailComponent = ({
</div>
</div>
<hr />
<div className="p-5 text-md">
<div className="p-5 text-md flex flex-col gap-4">
<ReactMarkdown rehypePlugins={[rehypeRaw]}>
{data.content}
</ReactMarkdown>
<div className="flex flex-col gap-2">
{isEventDetailPage &&
data.fileInfo.length > 0 &&
data.fileInfo.map((data, index) => (
<img src={data.url} key={index} className="w-70" />
))}
</div>
</div>
<hr />
{data.fileInfo.length > 0 &&
{!isEventDetailPage &&
data.fileInfo.length > 0 &&
data.fileInfo.map((data, index) => (
<a
className="flex flex-row items-center gap-1 pt-2 text-sm"
Expand Down
3 changes: 1 addition & 2 deletions src/features/content/ui/PdfViewerDetailComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ const PdfViewerDetailComponent = ({
<DateText date={formatDate(item.createAt)} />
</div>
<hr />
<PdfViewer pdf="/static/test.pdf" />
<PdfViewer pdf={item.fileInfo[0].url} />
<hr />

<div className="flex justify-end">
<BackToListButton />
</div>
Expand Down
12 changes: 12 additions & 0 deletions src/shared/api/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ instance.interceptors.response.use(
return;
}
}

if (
error.config.url.includes('transactions') ||
error.config.url.includes('notice') ||
error.config.url.includes('meetings') ||
error.config.url.includes('faq') ||
error.config.url.includes('event') ||
error.config.url.includes('rule') ||
error.config.url.includes('campusnotice')
) {
window.location.replace('/404');
}
return Promise.reject(error);
},
);

0 comments on commit dcc697a

Please sign in to comment.