новая версия api
This commit is contained in:
parent
5974125cbe
commit
72fbb34434
@ -310,21 +310,36 @@ export type CustomField = {
|
|||||||
Deleted: boolean;
|
Deleted: boolean;
|
||||||
CreatedAt: number;
|
CreatedAt: number;
|
||||||
};
|
};
|
||||||
|
export type Field = {
|
||||||
|
ID: number;
|
||||||
|
AmoID: number;
|
||||||
|
Code: string;
|
||||||
|
AccountID: number;
|
||||||
|
Name: string;
|
||||||
|
Entity: string;
|
||||||
|
Type: string;
|
||||||
|
Deleted: boolean;
|
||||||
|
CreatedAt: number;
|
||||||
|
};
|
||||||
|
|
||||||
export type CustomFieldsResponse = {
|
export type CustomFieldsResponse = {
|
||||||
count: number;
|
count: number;
|
||||||
items: CustomField[];
|
items: CustomField[];
|
||||||
};
|
};
|
||||||
|
export type FieldsResponse = {
|
||||||
|
count: number;
|
||||||
|
items: Field[];
|
||||||
|
};
|
||||||
|
|
||||||
export const getCustomFields = async (
|
export const getCustomFields = async (
|
||||||
pagination: PaginationRequest
|
pagination: PaginationRequest
|
||||||
): Promise<[CustomFieldsResponse | null, string?]> => {
|
): Promise<[CustomFieldsResponse | null, string?]> => {
|
||||||
try {
|
try {
|
||||||
const fieldsResponse = await makeRequest<PaginationRequest, CustomFieldsResponse>({
|
const customFieldsResponse = await makeRequest<PaginationRequest, CustomFieldsResponse>({
|
||||||
method: "GET",
|
method: "GET",
|
||||||
url: `${API_URL}/fields?page=${pagination.page}&size=${pagination.size}`,
|
url: `${API_URL}/fields?page=${pagination.page}&size=${pagination.size}`,
|
||||||
});
|
});
|
||||||
return [fieldsResponse];
|
return [customFieldsResponse];
|
||||||
} catch (nativeError) {
|
} catch (nativeError) {
|
||||||
const [error] = parseAxiosError(nativeError);
|
const [error] = parseAxiosError(nativeError);
|
||||||
return [null, `Не удалось получить список кастомных полей. ${error}`];
|
return [null, `Не удалось получить список кастомных полей. ${error}`];
|
||||||
@ -345,3 +360,17 @@ export const removeAmoAccount = async (): Promise<[void | null, string?]> => {
|
|||||||
return [null, `Не удалось отвязать аккаунт. ${error}`];
|
return [null, `Не удалось отвязать аккаунт. ${error}`];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export const getFields = async ( pagination: PaginationRequest ): Promise<[FieldsResponse | null, string?]> => {
|
||||||
|
try {
|
||||||
|
const fieldsResponse = await makeRequest<PaginationRequest, FieldsResponse>({
|
||||||
|
method: "GET",
|
||||||
|
url: `${API_URL}/fields?page=${pagination.page}&size=${pagination.size}`,
|
||||||
|
});
|
||||||
|
return [fieldsResponse, ""];
|
||||||
|
} catch (nativeError) {
|
||||||
|
const [error] = parseAxiosError(nativeError);
|
||||||
|
return [null, `Не удалось получить список полей. ${error}`];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@ -67,6 +67,7 @@ export const CustomRadioGroup: FC<CustomRadioGroupProps> = ({
|
|||||||
width: "200px",
|
width: "200px",
|
||||||
overflow: "hidden",
|
overflow: "hidden",
|
||||||
textOverflow: "ellipsis",
|
textOverflow: "ellipsis",
|
||||||
|
whiteSpace: "nowrap"
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
value={item.id}
|
value={item.id}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import React, { FC, useCallback, useEffect, useMemo, useState } from "react";
|
import React, { FC, useCallback, useEffect, useMemo, useState } from "react";
|
||||||
import {Dialog, IconButton, Typography, useMediaQuery, useTheme, Box, Skeleton} from "@mui/material";
|
import { Dialog, IconButton, Typography, useMediaQuery, useTheme, Box, Skeleton } from "@mui/material";
|
||||||
import { useQuestions } from "@/stores/questions/hooks";
|
import { useQuestions } from "@/stores/questions/hooks";
|
||||||
import { redirect } from "react-router-dom";
|
import { redirect } from "react-router-dom";
|
||||||
import { enqueueSnackbar } from "notistack";
|
import { enqueueSnackbar } from "notistack";
|
||||||
@ -35,18 +35,27 @@ import {
|
|||||||
} from "@api/integration";
|
} from "@api/integration";
|
||||||
import type { QuestionID } from "@api/integration";
|
import type { QuestionID } from "@api/integration";
|
||||||
import { useAmoIntegration } from "./useAmoIntegration";
|
import { useAmoIntegration } from "./useAmoIntegration";
|
||||||
import { QuestionKeys, TagKeys, TagQuestionHC } from "./types";
|
import { MinifiedData, QuestionKeys, TagKeys, TagQuestionHC } from "./types";
|
||||||
|
import { Quiz } from "@/model/quiz/quiz";
|
||||||
|
|
||||||
type IntegrationsModalProps = {
|
type IntegrationsModalProps = {
|
||||||
isModalOpen: boolean;
|
isModalOpen: boolean;
|
||||||
handleCloseModal: () => void;
|
handleCloseModal: () => void;
|
||||||
companyName: string | null;
|
companyName: string | null;
|
||||||
quizID: number | undefined;
|
quiz: Quiz;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const AmoCRMModal: FC<IntegrationsModalProps> = ({ isModalOpen, handleCloseModal, companyName, quizID }) => {
|
const FCTranslate = {
|
||||||
|
"name": "имя",
|
||||||
|
"email": "почта",
|
||||||
|
"phone": "телефон",
|
||||||
|
"text": "номер",
|
||||||
|
"address": "адрес",
|
||||||
|
}
|
||||||
|
|
||||||
|
export const AmoCRMModal: FC<IntegrationsModalProps> = ({ isModalOpen, handleCloseModal, companyName, quiz }) => {
|
||||||
//Если нет контекста квиза, то и делать на этой страничке нечего
|
//Если нет контекста квиза, то и делать на этой страничке нечего
|
||||||
if (quizID === undefined) {
|
if (quiz?.backendId === undefined) {
|
||||||
redirect("/list");
|
redirect("/list");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -66,12 +75,30 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({ isModalOpen, handleClo
|
|||||||
})),
|
})),
|
||||||
[questions]
|
[questions]
|
||||||
);
|
);
|
||||||
|
const FieldsAllowedFC = useMemo(
|
||||||
|
() => {
|
||||||
|
const list: MinifiedData[] = []
|
||||||
|
if (quiz.config.showfc) {
|
||||||
|
const fields = quiz.config.formContact.fields
|
||||||
|
for (let key in fields) {
|
||||||
|
if (fields[key].used) list.push({
|
||||||
|
id: key,
|
||||||
|
title: FCTranslate[key],
|
||||||
|
entity: "Contact",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
},
|
||||||
|
[quiz]
|
||||||
|
);
|
||||||
|
|
||||||
const [step, setStep] = useState<number>(5);
|
const [step, setStep] = useState<number>(5);
|
||||||
const [isSettingsBlock, setIsSettingsBlock] = useState<boolean>(false);
|
const [isSettingsBlock, setIsSettingsBlock] = useState<boolean>(false);
|
||||||
const [isTryRemoveAccount, setIsTryRemoveAccount] = useState<boolean>(false);
|
const [isTryRemoveAccount, setIsTryRemoveAccount] = useState<boolean>(false);
|
||||||
const [openDelete, setOpenDelete] = useState<TagQuestionHC | null>(null);
|
const [openDelete, setOpenDelete] = useState<TagQuestionHC | null>(null);
|
||||||
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
isLoadingPage,
|
isLoadingPage,
|
||||||
firstRules,
|
firstRules,
|
||||||
@ -80,8 +107,10 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({ isModalOpen, handleClo
|
|||||||
arrayOfPipelinesSteps,
|
arrayOfPipelinesSteps,
|
||||||
arrayOfUsers,
|
arrayOfUsers,
|
||||||
arrayOfTags,
|
arrayOfTags,
|
||||||
|
arrayOfFields,
|
||||||
selectedPipeline,
|
selectedPipeline,
|
||||||
setSelectedPipeline,
|
setSelectedPipeline,
|
||||||
|
selectedCurrentFields,
|
||||||
selectedPipelineStep,
|
selectedPipelineStep,
|
||||||
setSelectedPipelineStep,
|
setSelectedPipelineStep,
|
||||||
selectedDealUser,
|
selectedDealUser,
|
||||||
@ -95,10 +124,12 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({ isModalOpen, handleClo
|
|||||||
setPageOfPipelinesSteps,
|
setPageOfPipelinesSteps,
|
||||||
setPageOfUsers,
|
setPageOfUsers,
|
||||||
setPageOfTags,
|
setPageOfTags,
|
||||||
|
setSelectedCurrentFields,
|
||||||
} = useAmoIntegration({
|
} = useAmoIntegration({
|
||||||
quizID,
|
quizID: quiz.backendId,
|
||||||
isModalOpen,
|
isModalOpen,
|
||||||
isTryRemoveAccount,
|
isTryRemoveAccount,
|
||||||
|
questions,
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleAddTagQuestion = useCallback(
|
const handleAddTagQuestion = useCallback(
|
||||||
@ -135,6 +166,7 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({ isModalOpen, handleClo
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (openDelete.type === "question") {
|
if (openDelete.type === "question") {
|
||||||
|
console.log("delete id ", openDelete.id )
|
||||||
let newArray = selectedQuestions[openDelete.scope as QuestionKeys];
|
let newArray = selectedQuestions[openDelete.scope as QuestionKeys];
|
||||||
const index = newArray.indexOf(openDelete.id);
|
const index = newArray.indexOf(openDelete.id);
|
||||||
if (index !== -1) newArray.splice(index, 1);
|
if (index !== -1) newArray.splice(index, 1);
|
||||||
@ -143,6 +175,9 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({ isModalOpen, handleClo
|
|||||||
...prevState,
|
...prevState,
|
||||||
[openDelete.scope]: newArray,
|
[openDelete.scope]: newArray,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
setSelectedCurrentFields(selectedCurrentFields.filter(e => e.id !== openDelete.id));
|
||||||
|
|
||||||
}
|
}
|
||||||
setOpenDelete(null);
|
setOpenDelete(null);
|
||||||
}, [openDelete]);
|
}, [openDelete]);
|
||||||
@ -154,7 +189,7 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({ isModalOpen, handleClo
|
|||||||
setStep((prevState) => prevState - 1);
|
setStep((prevState) => prevState - 1);
|
||||||
};
|
};
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
if (quizID === undefined) return;
|
if (quiz?.backendId === undefined) return;
|
||||||
if (selectedPipeline === null) return enqueueSnackbar("Выберите воронку");
|
if (selectedPipeline === null) return enqueueSnackbar("Выберите воронку");
|
||||||
if (selectedPipeline === null) return enqueueSnackbar("Выберите этап воронки");
|
if (selectedPipeline === null) return enqueueSnackbar("Выберите этап воронки");
|
||||||
|
|
||||||
@ -167,29 +202,42 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({ isModalOpen, handleClo
|
|||||||
};
|
};
|
||||||
|
|
||||||
const FieldsRule = {
|
const FieldsRule = {
|
||||||
Company: [{ QuestionID: {} }],
|
Company: { QuestionID: {} },
|
||||||
Lead: [{ QuestionID: {} }],
|
Lead: { QuestionID: {} },
|
||||||
Customer: [{ QuestionID: {} }],
|
Customer: { QuestionID: {} },
|
||||||
|
Contact: {
|
||||||
|
QuestionID: {},
|
||||||
|
ContactRuleMap: {
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
for (let key in FieldsRule) {
|
for (let key in FieldsRule) {
|
||||||
selectedQuestions[key as QuestionKeys].forEach((id) => {
|
selectedQuestions[key as QuestionKeys].forEach((id) => {
|
||||||
FieldsRule[key as QuestionKeys][0].QuestionID[id] = 0;
|
FieldsRule[key as QuestionKeys].QuestionID[id] = 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
selectedCurrentFields.forEach((e) => {
|
||||||
|
FieldsRule.Contact.ContactRuleMap[e.subTitle] = Number(e.id)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
for (let key in body.TagsToAdd) {
|
for (let key in body.TagsToAdd) {
|
||||||
body.TagsToAdd[key as TagKeys] = body.TagsToAdd[key as TagKeys].map((id) => Number(id));
|
body.TagsToAdd[key as TagKeys] = body.TagsToAdd[key as TagKeys].map((id) => Number(id));
|
||||||
}
|
}
|
||||||
body.FieldsRule = FieldsRule;
|
body.FieldsRule = FieldsRule;
|
||||||
|
|
||||||
|
console.log(body)
|
||||||
|
|
||||||
if (firstRules) {
|
if (firstRules) {
|
||||||
setIntegrationRules(quizID.toString(), body);
|
setIntegrationRules(quiz.backendId.toString(), body);
|
||||||
} else {
|
} else {
|
||||||
updateIntegrationRules(quizID.toString(), body);
|
updateIntegrationRules(quiz.backendId.toString(), body);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleCloseModal();
|
handleCloseModal();
|
||||||
setStep(1);
|
setStep(1);
|
||||||
};
|
};
|
||||||
const steps = useMemo(
|
const steps = useMemo(
|
||||||
() => [
|
() => [
|
||||||
@ -258,7 +306,7 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({ isModalOpen, handleClo
|
|||||||
tagsItems={arrayOfTags}
|
tagsItems={arrayOfTags}
|
||||||
selectedTags={selectedTags}
|
selectedTags={selectedTags}
|
||||||
openDelete={setOpenDelete}
|
openDelete={setOpenDelete}
|
||||||
handleScroll={() => {}}
|
handleScroll={() => { }}
|
||||||
handleAddTag={handleAddTagQuestion}
|
handleAddTag={handleAddTagQuestion}
|
||||||
handlePrevStep={handlePrevStep}
|
handlePrevStep={handlePrevStep}
|
||||||
handleNextStep={handleNextStep}
|
handleNextStep={handleNextStep}
|
||||||
@ -270,12 +318,16 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({ isModalOpen, handleClo
|
|||||||
isSettingsAvailable: true,
|
isSettingsAvailable: true,
|
||||||
component: (
|
component: (
|
||||||
<AmoQuestions
|
<AmoQuestions
|
||||||
|
setSelectedCurrentFields={setSelectedCurrentFields}
|
||||||
|
fieldsItems={arrayOfFields}
|
||||||
|
selectedCurrentFields={selectedCurrentFields}
|
||||||
questionsItems={minifiedQuestions}
|
questionsItems={minifiedQuestions}
|
||||||
selectedQuestions={selectedQuestions}
|
selectedQuestions={selectedQuestions}
|
||||||
openDelete={setOpenDelete}
|
openDelete={setOpenDelete}
|
||||||
handleAddQuestion={handleAddTagQuestion}
|
handleAddQuestion={handleAddTagQuestion}
|
||||||
handlePrevStep={handlePrevStep}
|
handlePrevStep={handlePrevStep}
|
||||||
handleNextStep={handleSave}
|
handleNextStep={handleSave}
|
||||||
|
FieldsAllowedFC={FieldsAllowedFC}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@ -295,6 +347,7 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({ isModalOpen, handleClo
|
|||||||
arrayOfUsers,
|
arrayOfUsers,
|
||||||
minifiedQuestions,
|
minifiedQuestions,
|
||||||
arrayOfTags,
|
arrayOfTags,
|
||||||
|
selectedCurrentFields,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -355,52 +408,52 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({ isModalOpen, handleClo
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{isLoadingPage ?
|
{isLoadingPage ?
|
||||||
<Skeleton
|
<Skeleton
|
||||||
sx={{
|
sx={{
|
||||||
width: "100%",
|
width: "100%",
|
||||||
height: "100%",
|
height: "100%",
|
||||||
transform: "none",
|
transform: "none",
|
||||||
}}
|
}}
|
||||||
/> :
|
/> :
|
||||||
<>
|
<>
|
||||||
<AmoModalTitle
|
<AmoModalTitle
|
||||||
step={step}
|
step={step}
|
||||||
steps={steps}
|
steps={steps}
|
||||||
isSettingsBlock={isSettingsBlock}
|
isSettingsBlock={isSettingsBlock}
|
||||||
setIsSettingsBlock={setIsSettingsBlock}
|
setIsSettingsBlock={setIsSettingsBlock}
|
||||||
setStep={setStep}
|
setStep={setStep}
|
||||||
startRemoveAccount={() => setIsTryRemoveAccount(true)}
|
startRemoveAccount={() => setIsTryRemoveAccount(true)}
|
||||||
|
/>
|
||||||
|
{openDelete !== null ? (
|
||||||
|
<AmoDeleteTagQuestion
|
||||||
|
close={() => setOpenDelete(null)}
|
||||||
|
deleteItem={handleDeleteTagQuestion}
|
||||||
/>
|
/>
|
||||||
{openDelete !== null ? (
|
) : (
|
||||||
<AmoDeleteTagQuestion
|
<>
|
||||||
close={() => setOpenDelete(null)}
|
{isTryRemoveAccount && <AmoRemoveAccount stopThisPage={() => setIsTryRemoveAccount(false)} />}
|
||||||
deleteItem={handleDeleteTagQuestion}
|
{isSettingsBlock && (
|
||||||
/>
|
<Box sx={{ flexGrow: 1, width: "100%" }}>
|
||||||
) : (
|
<AmoSettingsBlock
|
||||||
<>
|
stepTitles={stepTitles}
|
||||||
{isTryRemoveAccount && <AmoRemoveAccount stopThisPage={() => setIsTryRemoveAccount(false)} />}
|
setIsSettingsBlock={setIsSettingsBlock}
|
||||||
{isSettingsBlock && (
|
setStep={setStep}
|
||||||
<Box sx={{ flexGrow: 1, width: "100%" }}>
|
selectedDealUser={arrayOfUsers.find((u) => u.id === selectedDealUser)?.title || "не указан"}
|
||||||
<AmoSettingsBlock
|
selectedFunnel={arrayOfPipelines.find((p) => p.id === selectedPipeline)?.title || "нет данных"}
|
||||||
stepTitles={stepTitles}
|
selectedStage={
|
||||||
setIsSettingsBlock={setIsSettingsBlock}
|
arrayOfPipelinesSteps.find((s) => s.id === selectedPipelineStep)?.title || "нет данных"
|
||||||
setStep={setStep}
|
}
|
||||||
selectedDealUser={arrayOfUsers.find((u) => u.id === selectedDealUser)?.title || "не указан"}
|
selectedQuestions={selectedQuestions}
|
||||||
selectedFunnel={arrayOfPipelines.find((p) => p.id === selectedPipeline)?.title || "нет данных"}
|
selectedTags={selectedTags}
|
||||||
selectedStage={
|
/>
|
||||||
arrayOfPipelinesSteps.find((s) => s.id === selectedPipelineStep)?.title || "нет данных"
|
</Box>
|
||||||
}
|
)}
|
||||||
selectedQuestions={selectedQuestions}
|
{!isSettingsBlock && !isTryRemoveAccount && (
|
||||||
selectedTags={selectedTags}
|
<Box sx={{ flexGrow: 1, width: "100%" }}>{steps[step].component}</Box>
|
||||||
/>
|
)}
|
||||||
</Box>
|
</>
|
||||||
)}
|
)}
|
||||||
{!isSettingsBlock && !isTryRemoveAccount && (
|
</>
|
||||||
<Box sx={{ flexGrow: 1, width: "100%" }}>{steps[step].component}</Box>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,41 +1,82 @@
|
|||||||
import { FC, useState } from "react";
|
import { FC, useMemo, useState } from "react";
|
||||||
import { ItemsSelectionView } from "./ItemsSelectionView/ItemsSelectionView";
|
import { ItemsSelectionView } from "./ItemsSelectionView/ItemsSelectionView";
|
||||||
import { ItemDetailsView } from "./ItemDetailsView/ItemDetailsView";
|
import { ItemDetailsView } from "./ItemDetailsView/ItemDetailsView";
|
||||||
import { Box } from "@mui/material";
|
import { Box } from "@mui/material";
|
||||||
import { QuestionKeys, SelectedQuestions, TagKeys, TagQuestionHC } from "../types";
|
import { MinifiedData, QuestionKeys, SelectedQuestions, TagKeys, TagQuestionHC } from "../types";
|
||||||
import { EntitiesQuestions } from "./EntitiesQuestions";
|
import { EntitiesQuestions } from "./EntitiesQuestions";
|
||||||
|
|
||||||
type MinifiedData = {
|
|
||||||
id: string;
|
|
||||||
title: string;
|
|
||||||
subTitle?: string;
|
|
||||||
};
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
selectedCurrentFields: MinifiedData[] | [];
|
||||||
questionsItems: MinifiedData[] | [];
|
questionsItems: MinifiedData[] | [];
|
||||||
|
fieldsItems: MinifiedData[] | [];
|
||||||
selectedQuestions: SelectedQuestions;
|
selectedQuestions: SelectedQuestions;
|
||||||
handleAddQuestion: (scope: QuestionKeys | TagKeys, id: string, type: "question" | "tag") => void;
|
handleAddQuestion: (scope: QuestionKeys | TagKeys, id: string, type: "question" | "tag") => void;
|
||||||
openDelete: (data: TagQuestionHC) => void;
|
openDelete: (data: TagQuestionHC) => void;
|
||||||
handlePrevStep: () => void;
|
handlePrevStep: () => void;
|
||||||
handleNextStep: () => void;
|
handleNextStep: () => void;
|
||||||
|
FieldsAllowedFC: MinifiedData[]
|
||||||
|
setSelectedCurrentFields: (value: MinifiedData[]) => void;
|
||||||
};
|
};
|
||||||
|
export type QuestionPair = {
|
||||||
|
question: string,
|
||||||
|
field: string
|
||||||
|
}
|
||||||
|
|
||||||
export const AmoQuestions: FC<Props> = ({
|
export const AmoQuestions: FC<Props> = ({
|
||||||
|
selectedCurrentFields,
|
||||||
questionsItems,
|
questionsItems,
|
||||||
|
fieldsItems,
|
||||||
selectedQuestions,
|
selectedQuestions,
|
||||||
handleAddQuestion,
|
handleAddQuestion,
|
||||||
handlePrevStep,
|
handlePrevStep,
|
||||||
handleNextStep,
|
handleNextStep,
|
||||||
openDelete,
|
openDelete,
|
||||||
|
FieldsAllowedFC,
|
||||||
|
setSelectedCurrentFields
|
||||||
}) => {
|
}) => {
|
||||||
|
console.log("selectedCurrentFields")
|
||||||
|
console.log(selectedCurrentFields)
|
||||||
|
console.log("selectedQuestions")
|
||||||
|
console.log(selectedQuestions)
|
||||||
const [isSelection, setIsSelection] = useState<boolean>(false);
|
const [isSelection, setIsSelection] = useState<boolean>(false);
|
||||||
const [activeScope, setActiveScope] = useState<QuestionKeys | null>(null);
|
const [activeScope, setActiveScope] = useState<QuestionKeys | null>(null);
|
||||||
const [selectedQuestion, setSelectedQuestion] = useState<string | null>(null);
|
const [selectedQuestion, setSelectedQuestion] = useState<string | null>(null);
|
||||||
|
const [selectedField, setSelectedField] = useState<string | null>(null);
|
||||||
|
|
||||||
const handleAdd = () => {
|
const [isCurrentFields, setIsCurrentFields] = useState(true);
|
||||||
|
|
||||||
|
const handleAddNewField = () => {
|
||||||
if (activeScope === null || selectedQuestion === null) return;
|
if (activeScope === null || selectedQuestion === null) return;
|
||||||
setActiveScope(null);
|
setActiveScope(null);
|
||||||
handleAddQuestion(activeScope, selectedQuestion, "question");
|
handleAddQuestion(activeScope, selectedQuestion, "question");
|
||||||
};
|
};
|
||||||
|
const handleAddCurrentField = () => {
|
||||||
|
if (activeScope === null || selectedField === null || selectedQuestion === null || selectedCurrentFields.some(e => e.id === selectedQuestion)) return;
|
||||||
|
setActiveScope(null);
|
||||||
|
setSelectedCurrentFields((old) => {
|
||||||
|
console.log(old)
|
||||||
|
return (
|
||||||
|
[...old, {
|
||||||
|
id: selectedQuestion,
|
||||||
|
title: questionsItems.find(e => e.id === selectedQuestion)?.title,
|
||||||
|
entity: activeScope,
|
||||||
|
subTitle: selectedField
|
||||||
|
}]
|
||||||
|
)
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAdd = () => {
|
||||||
|
console.log(activeScope, selectedQuestion)
|
||||||
|
if (isCurrentFields) {
|
||||||
|
console.log("добавляю текущее поле")
|
||||||
|
handleAddCurrentField()
|
||||||
|
} else {
|
||||||
|
console.log("добавляю новое поле")
|
||||||
|
handleAddNewField()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleDelete = (id: string, scope: QuestionKeys) => {
|
const handleDelete = (id: string, scope: QuestionKeys) => {
|
||||||
openDelete({
|
openDelete({
|
||||||
id,
|
id,
|
||||||
@ -43,6 +84,20 @@ export const AmoQuestions: FC<Props> = ({
|
|||||||
type: "question",
|
type: "question",
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
const SCFworld = useMemo(() => {
|
||||||
|
const obj = {
|
||||||
|
Lead: [],
|
||||||
|
Company: [],
|
||||||
|
Customer: [],
|
||||||
|
Contact: []
|
||||||
|
}
|
||||||
|
selectedCurrentFields.forEach((e) => {
|
||||||
|
if (!obj[e.entity]?.includes(e.id)) {
|
||||||
|
obj[e.entity].push(e.id)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return obj
|
||||||
|
}, [selectedCurrentFields])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
@ -55,10 +110,13 @@ export const AmoQuestions: FC<Props> = ({
|
|||||||
>
|
>
|
||||||
{isSelection && activeScope !== null ? (
|
{isSelection && activeScope !== null ? (
|
||||||
<EntitiesQuestions
|
<EntitiesQuestions
|
||||||
|
FieldsAllowedFC={FieldsAllowedFC}
|
||||||
|
fieldsItems={fieldsItems}
|
||||||
items={questionsItems}
|
items={questionsItems}
|
||||||
selectedItemId={selectedQuestion}
|
selectedItemId={selectedQuestion}
|
||||||
setSelectedItem={setSelectedQuestion}
|
setSelectedQuestion={setSelectedQuestion}
|
||||||
|
selectedField={selectedField}
|
||||||
|
setSelectedField={setSelectedField}
|
||||||
onSmallBtnClick={() => {
|
onSmallBtnClick={() => {
|
||||||
setActiveScope(null);
|
setActiveScope(null);
|
||||||
setIsSelection(false);
|
setIsSelection(false);
|
||||||
@ -68,6 +126,9 @@ export const AmoQuestions: FC<Props> = ({
|
|||||||
setActiveScope(null);
|
setActiveScope(null);
|
||||||
setIsSelection(false);
|
setIsSelection(false);
|
||||||
}}
|
}}
|
||||||
|
activeScope={activeScope}
|
||||||
|
setIsCurrentFields={setIsCurrentFields}
|
||||||
|
isCurrentFields={isCurrentFields}
|
||||||
/>
|
/>
|
||||||
// Здесь выбираем элемент в табличку
|
// Здесь выбираем элемент в табличку
|
||||||
// <ItemsSelectionView
|
// <ItemsSelectionView
|
||||||
@ -87,9 +148,14 @@ export const AmoQuestions: FC<Props> = ({
|
|||||||
) : (
|
) : (
|
||||||
// Табличка
|
// Табличка
|
||||||
<ItemDetailsView
|
<ItemDetailsView
|
||||||
items={questionsItems}
|
items={[...questionsItems, ...FieldsAllowedFC]}
|
||||||
setActiveScope={setActiveScope}
|
setActiveScope={setActiveScope}
|
||||||
selectedQuestions={selectedQuestions}
|
selectedQuestions={{
|
||||||
|
Lead: [...selectedQuestions.Lead, ...SCFworld.Lead],
|
||||||
|
Company: [...selectedQuestions.Company, ...SCFworld.Company],
|
||||||
|
Customer: [...selectedQuestions.Customer, ...SCFworld.Customer],
|
||||||
|
Contact: [...selectedQuestions.Contact, ...SCFworld.Contact]
|
||||||
|
}}
|
||||||
setIsSelection={setIsSelection}
|
setIsSelection={setIsSelection}
|
||||||
handleLargeBtn={handleNextStep}
|
handleLargeBtn={handleNextStep}
|
||||||
handleSmallBtn={handlePrevStep}
|
handleSmallBtn={handlePrevStep}
|
||||||
|
|||||||
@ -1,4 +1,81 @@
|
|||||||
|
import { CustomRadioGroup } from "@/components/CustomRadioGroup/CustomRadioGroup"
|
||||||
|
import { Box, Typography } from "@mui/material"
|
||||||
|
import { MinifiedData } from "../types";
|
||||||
|
|
||||||
export const CurrentFields = () => {
|
interface Props {
|
||||||
return <>мои поля</>
|
items: MinifiedData[];
|
||||||
|
fieldsItems: MinifiedData[];
|
||||||
|
currentField: string;
|
||||||
|
currentQuestion: string;
|
||||||
|
setCurrentField: (value: string) => void;
|
||||||
|
setCurrentQuestion: (value: string) => void;
|
||||||
|
}
|
||||||
|
export const CurrentFields = ({
|
||||||
|
items,
|
||||||
|
fieldsItems,
|
||||||
|
currentField,
|
||||||
|
currentQuestion,
|
||||||
|
setCurrentField,
|
||||||
|
setCurrentQuestion,
|
||||||
|
}: Props) => {
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "inline-flex",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
width: "100%",
|
||||||
|
height: "326px"
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
mr: "22px",
|
||||||
|
width: "50%"
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
sx={{
|
||||||
|
fontSize: "16px",
|
||||||
|
fontWeight: 400,
|
||||||
|
lineHeight: "18.96px",
|
||||||
|
textAlign: "left",
|
||||||
|
color: "#9A9AAF",
|
||||||
|
m: "15px 0 10px",
|
||||||
|
|
||||||
|
}}
|
||||||
|
>Выберите поле</Typography>
|
||||||
|
<CustomRadioGroup
|
||||||
|
items={fieldsItems}
|
||||||
|
selectedItemId={currentField}
|
||||||
|
setSelectedItem={setCurrentField}
|
||||||
|
handleScroll={() => { }}
|
||||||
|
activeScope={undefined}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
width: "50%"
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
sx={{
|
||||||
|
fontSize: "16px",
|
||||||
|
fontWeight: 400,
|
||||||
|
lineHeight: "18.96px",
|
||||||
|
textAlign: "left",
|
||||||
|
color: "#9A9AAF",
|
||||||
|
m: "15px 0 10px",
|
||||||
|
}}
|
||||||
|
>Выберите вопрос для этого поля</Typography>
|
||||||
|
<CustomRadioGroup
|
||||||
|
items={items}
|
||||||
|
selectedItemId={currentQuestion}
|
||||||
|
setSelectedItem={setCurrentQuestion}
|
||||||
|
handleScroll={() => { }}
|
||||||
|
activeScope={undefined}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
@ -1,37 +1,42 @@
|
|||||||
import { Box, Button } from "@mui/material"
|
import { Box, Button } from "@mui/material"
|
||||||
import { StepButtonsBlock } from "../StepButtonsBlock/StepButtonsBlock"
|
import { StepButtonsBlock } from "../StepButtonsBlock/StepButtonsBlock"
|
||||||
import { FC, useState } from "react";
|
import { FC, useState } from "react";
|
||||||
import { TagKeys } from "../types";
|
import { MinifiedData, TagKeys } from "../types";
|
||||||
import { CurrentFields } from "./CurrentFields";
|
import { CurrentFields } from "./CurrentFields";
|
||||||
import { NewFields } from "./NewFields";
|
import { NewFields } from "./NewFields";
|
||||||
|
import { QuestionPair } from "./AmoQuestions";
|
||||||
|
|
||||||
type MinifiedData = {
|
|
||||||
id: string;
|
|
||||||
title: string;
|
|
||||||
subTitle?: string;
|
|
||||||
};
|
|
||||||
type ItemsSelectionViewProps = {
|
type ItemsSelectionViewProps = {
|
||||||
items: MinifiedData[] | [];
|
items: MinifiedData[] | [];
|
||||||
|
fieldsItems: MinifiedData[] | [];
|
||||||
selectedItemId?: string | null;
|
selectedItemId?: string | null;
|
||||||
setSelectedItem: (value: string | null) => void;
|
setSelectedQuestion: (value: string | null) => void;
|
||||||
|
selectedField?: string | null;
|
||||||
|
setSelectedField: (value: string | null) => void;
|
||||||
handleScroll?: () => void;
|
handleScroll?: () => void;
|
||||||
onLargeBtnClick: () => void;
|
onLargeBtnClick: () => void;
|
||||||
onSmallBtnClick: () => void;
|
onSmallBtnClick: () => void;
|
||||||
activeScope: TagKeys;
|
activeScope: TagKeys;
|
||||||
};
|
FieldsAllowedFC: MinifiedData[];
|
||||||
|
setIsCurrentFields: (a:boolean) => void;
|
||||||
|
isCurrentFields: boolean
|
||||||
|
}
|
||||||
export const EntitiesQuestions: FC<ItemsSelectionViewProps> = ({
|
export const EntitiesQuestions: FC<ItemsSelectionViewProps> = ({
|
||||||
items,
|
items,
|
||||||
|
fieldsItems,
|
||||||
selectedItemId,
|
selectedItemId,
|
||||||
setSelectedItem,
|
setSelectedQuestion,
|
||||||
|
selectedField,
|
||||||
|
setSelectedField,
|
||||||
handleScroll,
|
handleScroll,
|
||||||
onLargeBtnClick,
|
onLargeBtnClick,
|
||||||
onSmallBtnClick,
|
onSmallBtnClick,
|
||||||
activeScope,
|
activeScope,
|
||||||
|
FieldsAllowedFC,
|
||||||
|
setIsCurrentFields,
|
||||||
|
isCurrentFields,
|
||||||
}) => {
|
}) => {
|
||||||
|
|
||||||
|
|
||||||
const [isCurrentFields, setIsCurrentFields] = useState(true);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
@ -77,9 +82,20 @@ export const EntitiesQuestions: FC<ItemsSelectionViewProps> = ({
|
|||||||
</Box>
|
</Box>
|
||||||
{
|
{
|
||||||
isCurrentFields ?
|
isCurrentFields ?
|
||||||
<CurrentFields />
|
<CurrentFields
|
||||||
|
items={items}
|
||||||
|
fieldsItems={[...FieldsAllowedFC, ...fieldsItems].filter(e => e.entity === activeScope)}
|
||||||
|
currentField={selectedField}
|
||||||
|
currentQuestion={selectedItemId}
|
||||||
|
setCurrentField={setSelectedField}
|
||||||
|
setCurrentQuestion={setSelectedQuestion}
|
||||||
|
/>
|
||||||
:
|
:
|
||||||
<NewFields />
|
<NewFields
|
||||||
|
items={items}
|
||||||
|
currentQuestion={selectedItemId}
|
||||||
|
setCurrentQuestion={setSelectedQuestion}
|
||||||
|
/>
|
||||||
}
|
}
|
||||||
</Box>
|
</Box>
|
||||||
<Box
|
<Box
|
||||||
@ -89,7 +105,9 @@ export const EntitiesQuestions: FC<ItemsSelectionViewProps> = ({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<StepButtonsBlock
|
<StepButtonsBlock
|
||||||
onLargeBtnClick={onLargeBtnClick}
|
onLargeBtnClick={() => {
|
||||||
|
onLargeBtnClick()
|
||||||
|
}}
|
||||||
largeBtnText={"Добавить"}
|
largeBtnText={"Добавить"}
|
||||||
onSmallBtnClick={onSmallBtnClick}
|
onSmallBtnClick={onSmallBtnClick}
|
||||||
smallBtnText={"Отменить"}
|
smallBtnText={"Отменить"}
|
||||||
|
|||||||
@ -25,6 +25,7 @@ export const ItemDetailsView: FC<ItemDetailsViewProps> = ({
|
|||||||
setActiveScope,
|
setActiveScope,
|
||||||
deleteHC,
|
deleteHC,
|
||||||
}) => {
|
}) => {
|
||||||
|
console.log(selectedQuestions)
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
7
src/pages/IntegrationsPage/IntegrationsModal/AmoQuestions/ItemsSelectionView/ItemsSelectionView.tsx
7
src/pages/IntegrationsPage/IntegrationsModal/AmoQuestions/ItemsSelectionView/ItemsSelectionView.tsx
@ -2,13 +2,8 @@ import { Box } from "@mui/material";
|
|||||||
import { CustomRadioGroup } from "../../../../../components/CustomRadioGroup/CustomRadioGroup";
|
import { CustomRadioGroup } from "../../../../../components/CustomRadioGroup/CustomRadioGroup";
|
||||||
import { StepButtonsBlock } from "../../StepButtonsBlock/StepButtonsBlock";
|
import { StepButtonsBlock } from "../../StepButtonsBlock/StepButtonsBlock";
|
||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
import { TagKeys } from "../../types";
|
import { MinifiedData, TagKeys } from "../../types";
|
||||||
|
|
||||||
type MinifiedData = {
|
|
||||||
id: string;
|
|
||||||
title: string;
|
|
||||||
subTitle?: string;
|
|
||||||
};
|
|
||||||
type ItemsSelectionViewProps = {
|
type ItemsSelectionViewProps = {
|
||||||
items: MinifiedData[] | [];
|
items: MinifiedData[] | [];
|
||||||
selectedItemId?: string | null;
|
selectedItemId?: string | null;
|
||||||
|
|||||||
@ -1,4 +1,53 @@
|
|||||||
|
import { CustomRadioGroup } from "@/components/CustomRadioGroup/CustomRadioGroup"
|
||||||
|
import { Box, Typography } from "@mui/material"
|
||||||
|
import { MinifiedData } from "../types";
|
||||||
|
|
||||||
export const NewFields = () => {
|
interface Props {
|
||||||
return <>новые поля</>
|
items: MinifiedData[];
|
||||||
|
fieldsItems: MinifiedData[];
|
||||||
|
currentField: string;
|
||||||
|
currentQuestion: string;
|
||||||
|
setCurrentField: (value: string) => void;
|
||||||
|
setCurrentQuestion: (value: string) => void;
|
||||||
|
}
|
||||||
|
export const NewFields = ({
|
||||||
|
items,
|
||||||
|
currentQuestion,
|
||||||
|
setCurrentQuestion,
|
||||||
|
}: Props) => {
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "inline-flex",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
width: "100%",
|
||||||
|
height: "326px"
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
width: "100%"
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
sx={{
|
||||||
|
fontSize: "16px",
|
||||||
|
fontWeight: 400,
|
||||||
|
lineHeight: "18.96px",
|
||||||
|
textAlign: "left",
|
||||||
|
color: "#9A9AAF",
|
||||||
|
m: "15px 0 10px",
|
||||||
|
}}
|
||||||
|
>Выберите вопрос для поля. Название поля настроится автоматически</Typography>
|
||||||
|
<CustomRadioGroup
|
||||||
|
items={items}
|
||||||
|
selectedItemId={currentQuestion}
|
||||||
|
setSelectedItem={setCurrentQuestion}
|
||||||
|
handleScroll={() => { }}
|
||||||
|
activeScope={undefined}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
export type TagKeys = "Contact" | "Company" | "Lead" | "Customer";
|
export type TagKeys = "Company" | "Lead" | "Customer" | "Contact";
|
||||||
export type SelectedTags = Record<TagKeys, number[]>;
|
export type SelectedTags = Record<TagKeys, number[]>;
|
||||||
|
|
||||||
export type QuestionKeys = "Company" | "Lead" | "Customer";
|
export type QuestionKeys = "Company" | "Lead" | "Customer" | "Contact";
|
||||||
export type SelectedQuestions = Record<QuestionKeys, string[]>;
|
export type SelectedQuestions = Record<QuestionKeys, string[]>;
|
||||||
|
|
||||||
export type MinifiedData = {
|
export type MinifiedData = {
|
||||||
|
|||||||
@ -10,17 +10,27 @@ import {
|
|||||||
getUsers,
|
getUsers,
|
||||||
getAccount,
|
getAccount,
|
||||||
FieldsRule,
|
FieldsRule,
|
||||||
|
getFields,
|
||||||
} from "@/api/integration";
|
} from "@/api/integration";
|
||||||
|
import { AnyTypedQuizQuestion } from "@frontend/squzanswerer";
|
||||||
|
|
||||||
const SIZE = 75;
|
const SIZE = 175;
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
isModalOpen: boolean;
|
isModalOpen: boolean;
|
||||||
isTryRemoveAccount: boolean;
|
isTryRemoveAccount: boolean;
|
||||||
quizID: number;
|
quizID: number;
|
||||||
|
questions: AnyTypedQuizQuestion
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useAmoIntegration = ({ isModalOpen, isTryRemoveAccount, quizID }: Props) => {
|
const FCTranslate = {
|
||||||
|
"name": "имя",
|
||||||
|
"email": "почта",
|
||||||
|
"phone": "телефон",
|
||||||
|
"text": "номер",
|
||||||
|
"address": "адрес",
|
||||||
|
}
|
||||||
|
export const useAmoIntegration = ({ isModalOpen, isTryRemoveAccount, quizID, questions }: Props) => {
|
||||||
const [isLoadingPage, setIsLoadingPage] = useState<boolean>(true);
|
const [isLoadingPage, setIsLoadingPage] = useState<boolean>(true);
|
||||||
const [firstRules, setFirstRules] = useState<boolean>(false);
|
const [firstRules, setFirstRules] = useState<boolean>(false);
|
||||||
const [accountInfo, setAccountInfo] = useState<AccountResponse | null>(null);
|
const [accountInfo, setAccountInfo] = useState<AccountResponse | null>(null);
|
||||||
@ -29,10 +39,12 @@ export const useAmoIntegration = ({ isModalOpen, isTryRemoveAccount, quizID }: P
|
|||||||
const [arrayOfPipelinesSteps, setArrayOfPipelinesSteps] = useState<MinifiedData[]>([]);
|
const [arrayOfPipelinesSteps, setArrayOfPipelinesSteps] = useState<MinifiedData[]>([]);
|
||||||
const [arrayOfUsers, setArrayOfUsers] = useState<MinifiedData[]>([]);
|
const [arrayOfUsers, setArrayOfUsers] = useState<MinifiedData[]>([]);
|
||||||
const [arrayOfTags, setArrayOfTags] = useState<MinifiedData[]>([]);
|
const [arrayOfTags, setArrayOfTags] = useState<MinifiedData[]>([]);
|
||||||
|
const [arrayOfFields, setArrayOfFields] = useState<MinifiedData[]>([]);
|
||||||
|
|
||||||
const [selectedPipeline, setSelectedPipeline] = useState<string | null>(null);
|
const [selectedPipeline, setSelectedPipeline] = useState<string | null>(null);
|
||||||
const [selectedPipelineStep, setSelectedPipelineStep] = useState<string | null>(null);
|
const [selectedPipelineStep, setSelectedPipelineStep] = useState<string | null>(null);
|
||||||
const [selectedDealUser, setSelectedDealPerformer] = useState<string | null>(null);
|
const [selectedDealUser, setSelectedDealPerformer] = useState<string | null>(null);
|
||||||
|
const [selectedCurrentFields, setSelectedCurrentFields] = useState<MinifiedData[]>([]);
|
||||||
|
|
||||||
const [questionsBackend, setQuestionsBackend] = useState<FieldsRule>({} as FieldsRule);
|
const [questionsBackend, setQuestionsBackend] = useState<FieldsRule>({} as FieldsRule);
|
||||||
const [selectedTags, setSelectedTags] = useState<SelectedTags>({
|
const [selectedTags, setSelectedTags] = useState<SelectedTags>({
|
||||||
@ -45,97 +57,88 @@ export const useAmoIntegration = ({ isModalOpen, isTryRemoveAccount, quizID }: P
|
|||||||
Lead: [],
|
Lead: [],
|
||||||
Company: [],
|
Company: [],
|
||||||
Customer: [],
|
Customer: [],
|
||||||
|
Contact: []
|
||||||
});
|
});
|
||||||
|
|
||||||
const [pageOfPipelines, setPageOfPipelines] = useState(1);
|
const [pageOfPipelines, setPageOfPipelines] = useState(1);
|
||||||
const [pageOfPipelinesSteps, setPageOfPipelinesSteps] = useState(1);
|
const [pageOfPipelinesSteps, setPageOfPipelinesSteps] = useState(1);
|
||||||
const [pageOfUsers, setPageOfUsers] = useState(1);
|
const [pageOfUsers, setPageOfUsers] = useState(1);
|
||||||
const [pageOfTags, setPageOfTags] = useState(1);
|
const [pageOfTags, setPageOfTags] = useState(1);
|
||||||
|
const [pageOfFields, setPageOfFields] = useState(1);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isModalOpen && !isTryRemoveAccount) {
|
const fetchAccountRules = async () => {
|
||||||
const fetchAccountRules = async () => {
|
setIsLoadingPage(true);
|
||||||
setIsLoadingPage(true);
|
const [account, accountError] = await getAccount();
|
||||||
const [account, accountError] = await getAccount();
|
|
||||||
|
|
||||||
if (accountError) {
|
if (accountError) {
|
||||||
if (!accountError.includes("Not Found")) enqueueSnackbar(accountError);
|
if (!accountError.includes("Not Found")) enqueueSnackbar(accountError);
|
||||||
setAccountInfo(null);
|
setAccountInfo(null);
|
||||||
}
|
}
|
||||||
if (account) {
|
if (account) {
|
||||||
setAccountInfo(account);
|
setAccountInfo(account);
|
||||||
}
|
}
|
||||||
const [settingsResponse, rulesError] = await getIntegrationRules(quizID.toString());
|
const [settingsResponse, rulesError] = await getIntegrationRules(quizID.toString());
|
||||||
|
|
||||||
if (rulesError) {
|
if (rulesError) {
|
||||||
if (rulesError === "first") setFirstRules(true);
|
if (rulesError === "first") setFirstRules(true);
|
||||||
if (!rulesError.includes("Not Found") && !rulesError.includes("first")) enqueueSnackbar(rulesError);
|
if (!rulesError.includes("Not Found") && !rulesError.includes("first")) enqueueSnackbar(rulesError);
|
||||||
}
|
}
|
||||||
if (settingsResponse) {
|
if (settingsResponse) {
|
||||||
if (settingsResponse.PipelineID) setSelectedPipeline(settingsResponse.PipelineID.toString());
|
if (settingsResponse.PipelineID) setSelectedPipeline(settingsResponse.PipelineID.toString());
|
||||||
if (settingsResponse.StepID) setSelectedPipelineStep(settingsResponse.StepID.toString());
|
if (settingsResponse.StepID) setSelectedPipelineStep(settingsResponse.StepID.toString());
|
||||||
if (settingsResponse.PerformerID) setSelectedDealPerformer(settingsResponse.PerformerID.toString());
|
if (settingsResponse.PerformerID) setSelectedDealPerformer(settingsResponse.PerformerID.toString());
|
||||||
|
|
||||||
if (Boolean(settingsResponse.FieldsRule) && Object.keys(settingsResponse?.FieldsRule).length > 0) {
|
if (Boolean(settingsResponse.FieldsRule) && Object.keys(settingsResponse?.FieldsRule).length > 0) {
|
||||||
const gottenQuestions = { ...selectedQuestions };
|
const gottenQuestions = { ...selectedQuestions };
|
||||||
setQuestionsBackend(settingsResponse.FieldsRule);
|
setQuestionsBackend(settingsResponse.FieldsRule);
|
||||||
|
|
||||||
for (let key in settingsResponse.FieldsRule) {
|
for (let key in settingsResponse.FieldsRule) {
|
||||||
if (
|
if (
|
||||||
settingsResponse.FieldsRule[key as QuestionKeys] !== null &&
|
settingsResponse.FieldsRule[key as QuestionKeys] !== null
|
||||||
Array.isArray(settingsResponse.FieldsRule[key as QuestionKeys])
|
) {
|
||||||
) {
|
const gottenList = settingsResponse.FieldsRule[key as QuestionKeys];
|
||||||
const gottenList = settingsResponse.FieldsRule[key as QuestionKeys];
|
|
||||||
|
|
||||||
if (gottenList !== null) gottenQuestions[key as QuestionKeys] = Object.keys(gottenList[0].QuestionID);
|
if (gottenList !== null) gottenQuestions[key as QuestionKeys] = Object.keys(gottenList.QuestionID);
|
||||||
|
|
||||||
|
if (key === "Contact") {
|
||||||
|
const MAP = settingsResponse.FieldsRule[key as QuestionKeys].ContactRuleMap
|
||||||
|
|
||||||
|
const list = []
|
||||||
|
for (let key in MAP) {
|
||||||
|
list.push({
|
||||||
|
id: MAP[key].toString(),
|
||||||
|
title: FCTranslate[key],
|
||||||
|
subTitle: key,
|
||||||
|
entity: "Contact",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
console.log(list)
|
||||||
|
setSelectedCurrentFields(list)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setSelectedQuestions(gottenQuestions);
|
|
||||||
}
|
}
|
||||||
|
setSelectedQuestions(gottenQuestions);
|
||||||
if (Boolean(settingsResponse.TagsToAdd) && Object.keys(settingsResponse.TagsToAdd).length > 0) {
|
|
||||||
const gottenTags = { ...selectedTags };
|
|
||||||
|
|
||||||
for (let key in settingsResponse.TagsToAdd) {
|
|
||||||
const gottenList = settingsResponse.TagsToAdd[key as TagKeys];
|
|
||||||
if (gottenList !== null && Array.isArray(gottenList)) {
|
|
||||||
gottenTags[key as TagKeys] = gottenList.map((e) => e.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setSelectedTags(gottenTags);
|
|
||||||
}
|
|
||||||
setFirstRules(false);
|
|
||||||
}
|
}
|
||||||
setIsLoadingPage(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchAccountRules();
|
if (Boolean(settingsResponse.TagsToAdd) && Object.keys(settingsResponse.TagsToAdd).length > 0) {
|
||||||
} else {
|
const gottenTags = { ...selectedTags };
|
||||||
//Вот по-хорошему компонент должен размонтироваться и стереть всё. Но это будет сделано позже
|
|
||||||
setArrayOfPipelines([]);
|
for (let key in settingsResponse.TagsToAdd) {
|
||||||
setArrayOfPipelinesSteps([]);
|
const gottenList = settingsResponse.TagsToAdd[key as TagKeys];
|
||||||
setArrayOfUsers([]);
|
if (gottenList !== null && Array.isArray(gottenList)) {
|
||||||
setArrayOfTags([]);
|
gottenTags[key as TagKeys] = gottenList.map((e) => e.toString());
|
||||||
setSelectedPipeline(null);
|
}
|
||||||
setSelectedPipelineStep(null);
|
}
|
||||||
setSelectedDealPerformer(null);
|
setSelectedTags(gottenTags);
|
||||||
setQuestionsBackend({} as FieldsRule);
|
}
|
||||||
setSelectedTags({
|
setFirstRules(false);
|
||||||
Lead: [],
|
}
|
||||||
Contact: [],
|
setIsLoadingPage(false);
|
||||||
Company: [],
|
};
|
||||||
Customer: [],
|
|
||||||
});
|
fetchAccountRules();
|
||||||
setSelectedQuestions({
|
|
||||||
Lead: [],
|
|
||||||
Company: [],
|
|
||||||
Customer: [],
|
|
||||||
});
|
|
||||||
setPageOfPipelines(1);
|
|
||||||
setPageOfPipelinesSteps(1);
|
|
||||||
setPageOfUsers(1);
|
|
||||||
setPageOfTags(1);
|
|
||||||
}
|
|
||||||
}, [isModalOpen, isTryRemoveAccount]);
|
}, [isModalOpen, isTryRemoveAccount]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -222,6 +225,32 @@ export const useAmoIntegration = ({ isModalOpen, isTryRemoveAccount, quizID }: P
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, [pageOfTags]);
|
}, [pageOfTags]);
|
||||||
|
useEffect(() => {
|
||||||
|
getFields({
|
||||||
|
page: pageOfTags,
|
||||||
|
size: SIZE,
|
||||||
|
}).then(([response]) => {
|
||||||
|
if (response && response.items !== null) {
|
||||||
|
const minifiedTags: MinifiedData[] = [];
|
||||||
|
|
||||||
|
response.items.forEach((field) => {
|
||||||
|
minifiedTags.push({
|
||||||
|
id: field.AmoID.toString(),
|
||||||
|
title: field.Name,
|
||||||
|
entity:
|
||||||
|
field.Entity === "leads"
|
||||||
|
? "Lead"
|
||||||
|
: field.Entity === "contacts"
|
||||||
|
? "Contact"
|
||||||
|
: field.Entity === "companies"
|
||||||
|
? "Company"
|
||||||
|
: "Customer",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
setArrayOfFields((prevItems) => [...prevItems, ...minifiedTags]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, [pageOfFields]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isLoadingPage,
|
isLoadingPage,
|
||||||
@ -231,8 +260,10 @@ export const useAmoIntegration = ({ isModalOpen, isTryRemoveAccount, quizID }: P
|
|||||||
arrayOfPipelinesSteps,
|
arrayOfPipelinesSteps,
|
||||||
arrayOfUsers,
|
arrayOfUsers,
|
||||||
arrayOfTags,
|
arrayOfTags,
|
||||||
|
arrayOfFields,
|
||||||
selectedPipeline,
|
selectedPipeline,
|
||||||
setSelectedPipeline,
|
setSelectedPipeline,
|
||||||
|
selectedCurrentFields,
|
||||||
selectedPipelineStep,
|
selectedPipelineStep,
|
||||||
setSelectedPipelineStep,
|
setSelectedPipelineStep,
|
||||||
selectedDealUser,
|
selectedDealUser,
|
||||||
@ -246,5 +277,6 @@ export const useAmoIntegration = ({ isModalOpen, isTryRemoveAccount, quizID }: P
|
|||||||
setPageOfPipelinesSteps,
|
setPageOfPipelinesSteps,
|
||||||
setPageOfUsers,
|
setPageOfUsers,
|
||||||
setPageOfTags,
|
setPageOfTags,
|
||||||
|
setSelectedCurrentFields,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -128,7 +128,7 @@ export const PartnersBoard: FC<PartnersBoardProps> = ({
|
|||||||
isModalOpen={isAmoCrmModalOpen}
|
isModalOpen={isAmoCrmModalOpen}
|
||||||
handleCloseModal={handleCloseAmoSRMModal}
|
handleCloseModal={handleCloseAmoSRMModal}
|
||||||
companyName={companyName}
|
companyName={companyName}
|
||||||
quizID={quiz?.backendId}
|
quiz={quiz}
|
||||||
/>
|
/>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user