2024-04-16 10:57:38 +00:00
|
|
|
import {
|
|
|
|
|
FC,
|
|
|
|
|
useState,
|
|
|
|
|
} from "react";
|
2024-06-04 00:08:24 +00:00
|
|
|
import { ItemsSelectionView } from "./ItemsSelectionView/ItemsSelectionView";
|
|
|
|
|
import { ItemDetailsView } from "./ItemDetailsView/ItemDetailsView";
|
2024-06-15 05:00:58 +00:00
|
|
|
import { Box } from "@mui/material";
|
|
|
|
|
import { QuestionKeys, SelectedQuestions, TagKeys } from "../types";
|
2024-04-12 15:07:37 +00:00
|
|
|
|
2024-06-15 05:00:58 +00:00
|
|
|
type Items = {
|
|
|
|
|
id: string;
|
|
|
|
|
title: string;
|
|
|
|
|
subTitle?: string;
|
|
|
|
|
};
|
2024-06-04 00:08:24 +00:00
|
|
|
type Props = {
|
2024-06-15 05:00:58 +00:00
|
|
|
questionsItems: Items[] | [];
|
|
|
|
|
selectedQuestions: SelectedQuestions;
|
|
|
|
|
handleAddQuestion: (scope: QuestionKeys | TagKeys, id: string, type: "question" | "tag") => void;
|
2024-06-04 00:08:24 +00:00
|
|
|
handlePrevStep: () => void;
|
|
|
|
|
handleNextStep: () => void;
|
2024-04-12 15:07:37 +00:00
|
|
|
};
|
|
|
|
|
|
2024-06-14 02:30:30 +00:00
|
|
|
export const AmoQuestions: FC<Props> = ({
|
2024-06-15 05:00:58 +00:00
|
|
|
questionsItems,
|
|
|
|
|
selectedQuestions,
|
|
|
|
|
handleAddQuestion,
|
2024-06-04 00:08:24 +00:00
|
|
|
handlePrevStep,
|
|
|
|
|
handleNextStep,
|
2024-04-12 15:07:37 +00:00
|
|
|
}) => {
|
2024-04-16 10:57:38 +00:00
|
|
|
const [isSelection, setIsSelection] = useState<boolean>(false);
|
2024-06-15 05:00:58 +00:00
|
|
|
const [activeScope, setActiveScope] = useState<QuestionKeys | null>(null);
|
|
|
|
|
const [selectedQuestion, setSelectedQuestion] = useState<string | null>(null);
|
2024-06-05 15:29:46 +00:00
|
|
|
|
2024-06-15 05:00:58 +00:00
|
|
|
const handleAdd = () => {
|
|
|
|
|
if (activeScope === null || selectedQuestion === null) return
|
|
|
|
|
handleAddQuestion(activeScope, selectedQuestion, "question")
|
|
|
|
|
}
|
2024-04-16 10:57:38 +00:00
|
|
|
|
2024-04-12 15:07:37 +00:00
|
|
|
return (
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
height: "100%",
|
|
|
|
|
flexGrow: 1,
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-06-15 05:00:58 +00:00
|
|
|
{isSelection && activeScope !== null ? (
|
|
|
|
|
// Здесь выбираем элемент в табличку
|
2024-04-16 10:57:38 +00:00
|
|
|
<ItemsSelectionView
|
2024-06-15 05:00:58 +00:00
|
|
|
items={questionsItems}
|
|
|
|
|
setSelectedItem={setSelectedQuestion}
|
2024-04-16 10:57:38 +00:00
|
|
|
onSmallBtnClick={() => {
|
2024-06-15 05:00:58 +00:00
|
|
|
setActiveScope(null);
|
2024-04-16 10:57:38 +00:00
|
|
|
setIsSelection(false);
|
|
|
|
|
}}
|
|
|
|
|
onLargeBtnClick={() => {
|
|
|
|
|
handleAdd();
|
2024-06-15 05:00:58 +00:00
|
|
|
setActiveScope(null);
|
2024-04-16 10:57:38 +00:00
|
|
|
setIsSelection(false);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
2024-06-15 05:00:58 +00:00
|
|
|
// Табличка
|
2024-06-04 00:08:24 +00:00
|
|
|
<ItemDetailsView
|
2024-06-15 05:00:58 +00:00
|
|
|
setActiveScope={setActiveScope}
|
|
|
|
|
selectedQuestions={selectedQuestions}
|
2024-04-16 10:57:38 +00:00
|
|
|
setIsSelection={setIsSelection}
|
2024-06-04 00:08:24 +00:00
|
|
|
handleLargeBtn={handleNextStep}
|
|
|
|
|
handleSmallBtn={handlePrevStep}
|
2024-04-12 15:07:37 +00:00
|
|
|
/>
|
2024-04-16 10:57:38 +00:00
|
|
|
)}
|
2024-04-12 15:07:37 +00:00
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|