mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
'use client';
|
|
|
|
import { useRouter, useSearchParams } from 'next/navigation';
|
|
import useSWR from 'swr';
|
|
|
|
import ExpenseDetail from '@/components/pages/expense/ExpenseDetail';
|
|
|
|
import { ExpenseApi } from '@/services/api/expense';
|
|
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
|
|
|
const ExpenseDetailPage = () => {
|
|
const router = useRouter();
|
|
const searchParams = useSearchParams();
|
|
|
|
const expenseId = searchParams.get('expenseId');
|
|
|
|
const { data: expense, isLoading: isLoadingExpense } = useSWR(
|
|
expenseId,
|
|
(id: number) => ExpenseApi.getSingle(id)
|
|
);
|
|
|
|
if (!expenseId) {
|
|
router.back();
|
|
|
|
return (
|
|
<div className='w-full flex flex-row justify-center items-center p-4'>
|
|
<span className='loading loading-spinner loading-xl' />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (!isLoadingExpense && (!expense || isResponseError(expense))) {
|
|
router.replace('/404');
|
|
return;
|
|
}
|
|
|
|
return (
|
|
<div className='w-full p-4 flex flex-row justify-center'>
|
|
{isLoadingExpense && (
|
|
<span className='loading loading-spinner loading-xl' />
|
|
)}
|
|
|
|
{!isLoadingExpense && isResponseSuccess(expense) && (
|
|
<ExpenseDetail initialValues={expense.data} />
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default ExpenseDetailPage;
|