2024-06-07 20:17:03 +03:00
|
|
|
|
'use client';
|
|
|
|
|
|
2025-01-26 22:24:34 +03:00
|
|
|
|
import axios from 'axios';
|
|
|
|
|
import { ErrorBoundary } from 'react-error-boundary';
|
2024-11-25 19:52:57 +03:00
|
|
|
|
import { useParams } from 'react-router';
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
2025-01-26 22:24:34 +03:00
|
|
|
|
import { useBlockNavigation, useConceptNavigation } from '@/app/Navigation/NavigationContext';
|
|
|
|
|
import { urls } from '@/app/urls';
|
2025-01-29 23:18:08 +03:00
|
|
|
|
import { ErrorData } from '@/components/info/InfoError';
|
2025-01-26 22:24:34 +03:00
|
|
|
|
import TextURL from '@/components/ui/TextURL';
|
|
|
|
|
import { useModificationStore } from '@/stores/modification';
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
2025-01-26 22:24:34 +03:00
|
|
|
|
import { OssEditState } from './OssEditContext';
|
2024-06-07 20:17:03 +03:00
|
|
|
|
import OssTabs from './OssTabs';
|
|
|
|
|
|
2025-01-29 23:18:08 +03:00
|
|
|
|
export function OssPage() {
|
2025-01-26 22:24:34 +03:00
|
|
|
|
const router = useConceptNavigation();
|
2024-06-07 20:17:03 +03:00
|
|
|
|
const params = useParams();
|
2025-01-23 19:41:31 +03:00
|
|
|
|
const itemID = params.id ? Number(params.id) : undefined;
|
2025-01-26 22:24:34 +03:00
|
|
|
|
|
|
|
|
|
const { isModified } = useModificationStore();
|
|
|
|
|
useBlockNavigation(isModified);
|
|
|
|
|
|
|
|
|
|
if (!itemID) {
|
|
|
|
|
router.replace(urls.page404);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-07 20:17:03 +03:00
|
|
|
|
return (
|
2025-01-26 22:24:34 +03:00
|
|
|
|
<ErrorBoundary FallbackComponent={ProcessError}>
|
|
|
|
|
<OssEditState itemID={itemID}>
|
2025-01-23 19:41:31 +03:00
|
|
|
|
<OssTabs />
|
2025-01-26 22:24:34 +03:00
|
|
|
|
</OssEditState>
|
|
|
|
|
</ErrorBoundary>
|
2024-06-07 20:17:03 +03:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-26 22:24:34 +03:00
|
|
|
|
// ====== Internals =========
|
|
|
|
|
function ProcessError({ error }: { error: ErrorData }): React.ReactElement {
|
|
|
|
|
if (axios.isAxiosError(error) && error.response) {
|
|
|
|
|
if (error.response.status === 404) {
|
|
|
|
|
return (
|
|
|
|
|
<div className='flex flex-col items-center p-2 mx-auto'>
|
|
|
|
|
<p>{`Операционная схема с указанным идентификатором отсутствует`}</p>
|
|
|
|
|
<div className='flex justify-center'>
|
|
|
|
|
<TextURL text='Библиотека' href='/library' />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
} else if (error.response.status === 403) {
|
|
|
|
|
return (
|
|
|
|
|
<div className='flex flex-col items-center p-2 mx-auto'>
|
|
|
|
|
<p>Владелец ограничил доступ к данной схеме</p>
|
|
|
|
|
<TextURL text='Библиотека' href='/library' />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-01-29 23:18:08 +03:00
|
|
|
|
throw error as Error;
|
2025-01-26 22:24:34 +03:00
|
|
|
|
}
|