frontPanel/src/pages/IntegrationsPage/IntegrationsModal/AmoQuestions/AmoQuestions.tsx

86 lines
2.4 KiB
TypeScript
Raw Normal View History

import { FC, useState } from "react";
import { ItemsSelectionView } from "./ItemsSelectionView/ItemsSelectionView";
import { ItemDetailsView } from "./ItemDetailsView/ItemDetailsView";
import { Box } from "@mui/material";
import { QuestionKeys, SelectedQuestions, TagKeys, TagQuestionHC } from "../types";
2024-04-12 15:07:37 +00:00
type MinifiedData = {
id: string;
title: string;
subTitle?: string;
};
type Props = {
questionsItems: MinifiedData[] | [];
selectedQuestions: SelectedQuestions;
handleAddQuestion: (scope: QuestionKeys | TagKeys, id: string, type: "question" | "tag") => void;
openDelete: (data: TagQuestionHC) => void;
handlePrevStep: () => void;
handleNextStep: () => void;
2024-04-12 15:07:37 +00:00
};
export const AmoQuestions: FC<Props> = ({
questionsItems,
selectedQuestions,
handleAddQuestion,
handlePrevStep,
handleNextStep,
openDelete,
2024-04-12 15:07:37 +00:00
}) => {
2024-04-16 10:57:38 +00:00
const [isSelection, setIsSelection] = useState<boolean>(false);
const [activeScope, setActiveScope] = useState<QuestionKeys | null>(null);
const [selectedQuestion, setSelectedQuestion] = useState<string | null>(null);
const handleAdd = () => {
if (activeScope === null || selectedQuestion === null) return;
setActiveScope(null);
handleAddQuestion(activeScope, selectedQuestion, "question");
};
const handleDelete = (id: string, scope: QuestionKeys) => {
openDelete({
id,
scope,
type: "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,
}}
>
{isSelection && activeScope !== null ? (
// Здесь выбираем элемент в табличку
2024-04-16 10:57:38 +00:00
<ItemsSelectionView
items={questionsItems}
selectedItemId={selectedQuestion}
setSelectedItem={setSelectedQuestion}
2024-04-16 10:57:38 +00:00
onSmallBtnClick={() => {
setActiveScope(null);
2024-04-16 10:57:38 +00:00
setIsSelection(false);
}}
onLargeBtnClick={() => {
handleAdd();
setActiveScope(null);
2024-04-16 10:57:38 +00:00
setIsSelection(false);
}}
/>
) : (
// Табличка
<ItemDetailsView
items={questionsItems}
setActiveScope={setActiveScope}
selectedQuestions={selectedQuestions}
2024-04-16 10:57:38 +00:00
setIsSelection={setIsSelection}
handleLargeBtn={handleNextStep}
handleSmallBtn={handlePrevStep}
deleteHC={handleDelete}
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>
);
};