2024-06-07 20:17:03 +03:00
|
|
|
|
'use client';
|
|
|
|
|
|
2025-01-30 19:22:49 +03:00
|
|
|
|
import { useEffect } from 'react';
|
2025-01-26 22:24:34 +03:00
|
|
|
|
import { ErrorBoundary } from 'react-error-boundary';
|
2024-11-25 19:52:57 +03:00
|
|
|
|
import { useParams } from 'react-router';
|
2025-01-30 19:22:49 +03:00
|
|
|
|
import { z } from 'zod';
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
2025-02-10 01:32:16 +03:00
|
|
|
|
import { urls, useBlockNavigation, useConceptNavigation } from '@/app';
|
2025-02-26 20:34:58 +03:00
|
|
|
|
import { ConstituentaTooltip } from '@/features/rsform/components';
|
2025-02-12 21:36:03 +03:00
|
|
|
|
|
2025-03-12 11:54:32 +03:00
|
|
|
|
import { isAxiosError } from '@/backend/api-transport';
|
2025-03-12 12:04:23 +03:00
|
|
|
|
import { TextURL } from '@/components/control';
|
2025-03-12 11:54:32 +03:00
|
|
|
|
import { type ErrorData } from '@/components/info-error';
|
|
|
|
|
import { useQueryStrings } from '@/hooks/use-query-strings';
|
2025-01-26 22:24:34 +03:00
|
|
|
|
import { useModificationStore } from '@/stores/modification';
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
2025-03-12 11:54:32 +03:00
|
|
|
|
import { OperationTooltip } from '../../components/operation-tooltip';
|
2025-02-26 20:34:58 +03:00
|
|
|
|
|
2025-04-07 21:46:19 +03:00
|
|
|
|
import { OssTabID } from './oss-edit-context';
|
|
|
|
|
import { OssEditState } from './oss-edit-state';
|
2025-03-12 11:54:32 +03:00
|
|
|
|
import { OssTabs } from './oss-tabs';
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
2025-03-02 19:07:12 +03:00
|
|
|
|
const paramsSchema = z.strictObject({
|
2025-01-30 20:06:00 +03:00
|
|
|
|
id: z.coerce.number(),
|
2025-02-12 20:53:01 +03:00
|
|
|
|
tab: z.preprocess(v => (v ? Number(v) : undefined), z.nativeEnum(OssTabID).default(OssTabID.GRAPH))
|
2025-01-30 19:22:49 +03:00
|
|
|
|
});
|
|
|
|
|
|
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-30 19:22:49 +03:00
|
|
|
|
const query = useQueryStrings();
|
|
|
|
|
|
|
|
|
|
const urlData = paramsSchema.parse({
|
|
|
|
|
id: params.id,
|
|
|
|
|
tab: query.get('tab')
|
|
|
|
|
});
|
2025-01-26 22:24:34 +03:00
|
|
|
|
|
2025-01-30 19:22:49 +03:00
|
|
|
|
const { isModified, setIsModified } = useModificationStore();
|
2025-01-26 22:24:34 +03:00
|
|
|
|
useBlockNavigation(isModified);
|
|
|
|
|
|
2025-01-30 19:22:49 +03:00
|
|
|
|
useEffect(() => setIsModified(false), [setIsModified]);
|
|
|
|
|
|
|
|
|
|
if (!urlData.id) {
|
2025-02-26 16:28:16 +03:00
|
|
|
|
router.replace({ path: urls.page404, force: true });
|
2025-01-26 22:24:34 +03:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-07 20:17:03 +03:00
|
|
|
|
return (
|
2025-01-26 22:24:34 +03:00
|
|
|
|
<ErrorBoundary FallbackComponent={ProcessError}>
|
2025-02-26 20:34:58 +03:00
|
|
|
|
<OperationTooltip />
|
|
|
|
|
<ConstituentaTooltip />
|
2025-01-30 19:22:49 +03:00
|
|
|
|
<OssEditState itemID={urlData.id}>
|
|
|
|
|
<OssTabs activeTab={urlData.tab} />
|
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 {
|
2025-02-10 01:32:16 +03:00
|
|
|
|
if (isAxiosError(error) && error.response) {
|
2025-01-26 22:24:34 +03:00
|
|
|
|
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
|
|
|
|
}
|