Merge remote-tracking branch 'origin/main' into left-panel
# Conflicts: # src/webparts/requestPortal/components/RequestPortal.tsx
This commit is contained in:
@@ -1,24 +1,34 @@
|
||||
import * as React from 'react';
|
||||
import { useState } from 'react';
|
||||
import { useState, useMemo } from 'react';
|
||||
import type { WebPartContext } from '@microsoft/sp-webpart-base';
|
||||
import styles from './SubmitFeature.module.scss';
|
||||
import { Icon } from '../../shared/ui/Icon/Icon';
|
||||
import { CategoryTabs } from '../../components/CategoryTabs/CategoryTabs';
|
||||
import { RequestGrid } from '../../components/RequestGrid/RequestGrid';
|
||||
import { CATEGORIES, DEFAULT_CATEGORY_ID } from '../../data/categories';
|
||||
import { getRequestsByCategory } from '../../data/requests';
|
||||
import { getRequestsByCategory, REQUEST_TYPES } from '../../data/requests';
|
||||
import { getFormComponent } from '../../forms/registry';
|
||||
import { IRequestType } from '../../models/types';
|
||||
|
||||
export interface ISubmitFeatureProps {
|
||||
context: WebPartContext;
|
||||
/** Открыть сразу форму с предзаполнением (производная заявка), минуя плитки. */
|
||||
initialForm?: { formKey: string; sourceId: number };
|
||||
}
|
||||
|
||||
// Фича «Подать заявку»: категории → плитки → беспоук-форма.
|
||||
// Владелец: автор портала. Живёт целиком в features/submit/**.
|
||||
const SubmitFeature: React.FC<ISubmitFeatureProps> = ({ context }) => {
|
||||
const [activeCategoryId, setActiveCategoryId] = useState<string>(DEFAULT_CATEGORY_ID);
|
||||
const [selectedRequest, setSelectedRequest] = useState<IRequestType | null>(null);
|
||||
const SubmitFeature: React.FC<ISubmitFeatureProps> = ({ context, initialForm }) => {
|
||||
// Если пришли по ссылке «создать на основе» — сразу открываем нужную форму.
|
||||
const initialSelected = useMemo(
|
||||
() => (initialForm ? REQUEST_TYPES.filter((r) => r.id === initialForm.formKey)[0] ?? null : null),
|
||||
[initialForm]
|
||||
);
|
||||
|
||||
const [activeCategoryId, setActiveCategoryId] = useState<string>(
|
||||
initialSelected ? initialSelected.categoryId : DEFAULT_CATEGORY_ID
|
||||
);
|
||||
const [selectedRequest, setSelectedRequest] = useState<IRequestType | null>(initialSelected);
|
||||
|
||||
const requests = getRequestsByCategory(activeCategoryId);
|
||||
|
||||
@@ -45,10 +55,14 @@ const SubmitFeature: React.FC<ISubmitFeatureProps> = ({ context }) => {
|
||||
);
|
||||
}
|
||||
|
||||
// sourceId — только для формы, открытой «на основе» исходной заявки.
|
||||
const sourceId =
|
||||
initialForm && request.id === initialForm.formKey ? initialForm.sourceId : undefined;
|
||||
|
||||
// Ленивый рендер формы: её код подтягивается только сейчас, при открытии.
|
||||
return (
|
||||
<React.Suspense fallback={<div className={styles.loading}>Загрузка формы…</div>}>
|
||||
<FormComponent requestType={request} context={context} onCancel={handleBack} />
|
||||
<FormComponent requestType={request} context={context} onCancel={handleBack} sourceId={sourceId} />
|
||||
</React.Suspense>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user