новая версия api
This commit is contained in:
parent
5974125cbe
commit
72fbb34434
@ -310,21 +310,36 @@ export type CustomField = {
|
||||
Deleted: boolean;
|
||||
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 = {
|
||||
count: number;
|
||||
items: CustomField[];
|
||||
};
|
||||
export type FieldsResponse = {
|
||||
count: number;
|
||||
items: Field[];
|
||||
};
|
||||
|
||||
export const getCustomFields = async (
|
||||
pagination: PaginationRequest
|
||||
): Promise<[CustomFieldsResponse | null, string?]> => {
|
||||
try {
|
||||
const fieldsResponse = await makeRequest<PaginationRequest, CustomFieldsResponse>({
|
||||
const customFieldsResponse = await makeRequest<PaginationRequest, CustomFieldsResponse>({
|
||||
method: "GET",
|
||||
url: `${API_URL}/fields?page=${pagination.page}&size=${pagination.size}`,
|
||||
});
|
||||
return [fieldsResponse];
|
||||
return [customFieldsResponse];
|
||||
} catch (nativeError) {
|
||||
const [error] = parseAxiosError(nativeError);
|
||||
return [null, `Не удалось получить список кастомных полей. ${error}`];
|
||||
@ -345,3 +360,17 @@ export const removeAmoAccount = async (): Promise<[void | null, string?]> => {
|
||||
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",
|
||||
overflow: "hidden",
|
||||
textOverflow: "ellipsis",
|
||||
whiteSpace: "nowrap"
|
||||
},
|
||||
}}
|
||||
value={item.id}
|
||||
|
||||
@ -35,18 +35,27 @@ import {
|
||||
} from "@api/integration";
|
||||
import type { QuestionID } from "@api/integration";
|
||||
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 = {
|
||||
isModalOpen: boolean;
|
||||
handleCloseModal: () => void;
|
||||
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");
|
||||
return null;
|
||||
}
|
||||
@ -66,12 +75,30 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({ isModalOpen, handleClo
|
||||
})),
|
||||
[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 [isSettingsBlock, setIsSettingsBlock] = useState<boolean>(false);
|
||||
const [isTryRemoveAccount, setIsTryRemoveAccount] = useState<boolean>(false);
|
||||
const [openDelete, setOpenDelete] = useState<TagQuestionHC | null>(null);
|
||||
|
||||
|
||||
const {
|
||||
isLoadingPage,
|
||||
firstRules,
|
||||
@ -80,8 +107,10 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({ isModalOpen, handleClo
|
||||
arrayOfPipelinesSteps,
|
||||
arrayOfUsers,
|
||||
arrayOfTags,
|
||||
arrayOfFields,
|
||||
selectedPipeline,
|
||||
setSelectedPipeline,
|
||||
selectedCurrentFields,
|
||||
selectedPipelineStep,
|
||||
setSelectedPipelineStep,
|
||||
selectedDealUser,
|
||||
@ -95,10 +124,12 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({ isModalOpen, handleClo
|
||||
setPageOfPipelinesSteps,
|
||||
setPageOfUsers,
|
||||
setPageOfTags,
|
||||
setSelectedCurrentFields,
|
||||
} = useAmoIntegration({
|
||||
quizID,
|
||||
quizID: quiz.backendId,
|
||||
isModalOpen,
|
||||
isTryRemoveAccount,
|
||||
questions,
|
||||
});
|
||||
|
||||
const handleAddTagQuestion = useCallback(
|
||||
@ -135,6 +166,7 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({ isModalOpen, handleClo
|
||||
}
|
||||
|
||||
if (openDelete.type === "question") {
|
||||
console.log("delete id ", openDelete.id )
|
||||
let newArray = selectedQuestions[openDelete.scope as QuestionKeys];
|
||||
const index = newArray.indexOf(openDelete.id);
|
||||
if (index !== -1) newArray.splice(index, 1);
|
||||
@ -143,6 +175,9 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({ isModalOpen, handleClo
|
||||
...prevState,
|
||||
[openDelete.scope]: newArray,
|
||||
}));
|
||||
|
||||
setSelectedCurrentFields(selectedCurrentFields.filter(e => e.id !== openDelete.id));
|
||||
|
||||
}
|
||||
setOpenDelete(null);
|
||||
}, [openDelete]);
|
||||
@ -154,7 +189,7 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({ isModalOpen, handleClo
|
||||
setStep((prevState) => prevState - 1);
|
||||
};
|
||||
const handleSave = () => {
|
||||
if (quizID === undefined) return;
|
||||
if (quiz?.backendId === undefined) return;
|
||||
if (selectedPipeline === null) return enqueueSnackbar("Выберите воронку");
|
||||
if (selectedPipeline === null) return enqueueSnackbar("Выберите этап воронки");
|
||||
|
||||
@ -167,25 +202,38 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({ isModalOpen, handleClo
|
||||
};
|
||||
|
||||
const FieldsRule = {
|
||||
Company: [{ QuestionID: {} }],
|
||||
Lead: [{ QuestionID: {} }],
|
||||
Customer: [{ QuestionID: {} }],
|
||||
Company: { QuestionID: {} },
|
||||
Lead: { QuestionID: {} },
|
||||
Customer: { QuestionID: {} },
|
||||
Contact: {
|
||||
QuestionID: {},
|
||||
ContactRuleMap: {
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
for (let key in FieldsRule) {
|
||||
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) {
|
||||
body.TagsToAdd[key as TagKeys] = body.TagsToAdd[key as TagKeys].map((id) => Number(id));
|
||||
}
|
||||
body.FieldsRule = FieldsRule;
|
||||
|
||||
console.log(body)
|
||||
|
||||
if (firstRules) {
|
||||
setIntegrationRules(quizID.toString(), body);
|
||||
setIntegrationRules(quiz.backendId.toString(), body);
|
||||
} else {
|
||||
updateIntegrationRules(quizID.toString(), body);
|
||||
updateIntegrationRules(quiz.backendId.toString(), body);
|
||||
}
|
||||
|
||||
handleCloseModal();
|
||||
@ -270,12 +318,16 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({ isModalOpen, handleClo
|
||||
isSettingsAvailable: true,
|
||||
component: (
|
||||
<AmoQuestions
|
||||
setSelectedCurrentFields={setSelectedCurrentFields}
|
||||
fieldsItems={arrayOfFields}
|
||||
selectedCurrentFields={selectedCurrentFields}
|
||||
questionsItems={minifiedQuestions}
|
||||
selectedQuestions={selectedQuestions}
|
||||
openDelete={setOpenDelete}
|
||||
handleAddQuestion={handleAddTagQuestion}
|
||||
handlePrevStep={handlePrevStep}
|
||||
handleNextStep={handleSave}
|
||||
FieldsAllowedFC={FieldsAllowedFC}
|
||||
/>
|
||||
),
|
||||
},
|
||||
@ -295,6 +347,7 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({ isModalOpen, handleClo
|
||||
arrayOfUsers,
|
||||
minifiedQuestions,
|
||||
arrayOfTags,
|
||||
selectedCurrentFields,
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
@ -1,41 +1,82 @@
|
||||
import { FC, useState } from "react";
|
||||
import { FC, useMemo, 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";
|
||||
import { MinifiedData, QuestionKeys, SelectedQuestions, TagKeys, TagQuestionHC } from "../types";
|
||||
import { EntitiesQuestions } from "./EntitiesQuestions";
|
||||
|
||||
type MinifiedData = {
|
||||
id: string;
|
||||
title: string;
|
||||
subTitle?: string;
|
||||
};
|
||||
type Props = {
|
||||
selectedCurrentFields: MinifiedData[] | [];
|
||||
questionsItems: MinifiedData[] | [];
|
||||
fieldsItems: MinifiedData[] | [];
|
||||
selectedQuestions: SelectedQuestions;
|
||||
handleAddQuestion: (scope: QuestionKeys | TagKeys, id: string, type: "question" | "tag") => void;
|
||||
openDelete: (data: TagQuestionHC) => void;
|
||||
handlePrevStep: () => void;
|
||||
handleNextStep: () => void;
|
||||
FieldsAllowedFC: MinifiedData[]
|
||||
setSelectedCurrentFields: (value: MinifiedData[]) => void;
|
||||
};
|
||||
export type QuestionPair = {
|
||||
question: string,
|
||||
field: string
|
||||
}
|
||||
|
||||
export const AmoQuestions: FC<Props> = ({
|
||||
selectedCurrentFields,
|
||||
questionsItems,
|
||||
fieldsItems,
|
||||
selectedQuestions,
|
||||
handleAddQuestion,
|
||||
handlePrevStep,
|
||||
handleNextStep,
|
||||
openDelete,
|
||||
FieldsAllowedFC,
|
||||
setSelectedCurrentFields
|
||||
}) => {
|
||||
console.log("selectedCurrentFields")
|
||||
console.log(selectedCurrentFields)
|
||||
console.log("selectedQuestions")
|
||||
console.log(selectedQuestions)
|
||||
const [isSelection, setIsSelection] = useState<boolean>(false);
|
||||
const [activeScope, setActiveScope] = useState<QuestionKeys | 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;
|
||||
setActiveScope(null);
|
||||
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) => {
|
||||
openDelete({
|
||||
id,
|
||||
@ -43,6 +84,20 @@ export const AmoQuestions: FC<Props> = ({
|
||||
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 (
|
||||
<Box
|
||||
@ -55,10 +110,13 @@ export const AmoQuestions: FC<Props> = ({
|
||||
>
|
||||
{isSelection && activeScope !== null ? (
|
||||
<EntitiesQuestions
|
||||
|
||||
FieldsAllowedFC={FieldsAllowedFC}
|
||||
fieldsItems={fieldsItems}
|
||||
items={questionsItems}
|
||||
selectedItemId={selectedQuestion}
|
||||
setSelectedItem={setSelectedQuestion}
|
||||
setSelectedQuestion={setSelectedQuestion}
|
||||
selectedField={selectedField}
|
||||
setSelectedField={setSelectedField}
|
||||
onSmallBtnClick={() => {
|
||||
setActiveScope(null);
|
||||
setIsSelection(false);
|
||||
@ -68,6 +126,9 @@ export const AmoQuestions: FC<Props> = ({
|
||||
setActiveScope(null);
|
||||
setIsSelection(false);
|
||||
}}
|
||||
activeScope={activeScope}
|
||||
setIsCurrentFields={setIsCurrentFields}
|
||||
isCurrentFields={isCurrentFields}
|
||||
/>
|
||||
// Здесь выбираем элемент в табличку
|
||||
// <ItemsSelectionView
|
||||
@ -87,9 +148,14 @@ export const AmoQuestions: FC<Props> = ({
|
||||
) : (
|
||||
// Табличка
|
||||
<ItemDetailsView
|
||||
items={questionsItems}
|
||||
items={[...questionsItems, ...FieldsAllowedFC]}
|
||||
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}
|
||||
handleLargeBtn={handleNextStep}
|
||||
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 = () => {
|
||||
return <>мои поля</>
|
||||
interface Props {
|
||||
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 { StepButtonsBlock } from "../StepButtonsBlock/StepButtonsBlock"
|
||||
import { FC, useState } from "react";
|
||||
import { TagKeys } from "../types";
|
||||
import { MinifiedData, TagKeys } from "../types";
|
||||
import { CurrentFields } from "./CurrentFields";
|
||||
import { NewFields } from "./NewFields";
|
||||
import { QuestionPair } from "./AmoQuestions";
|
||||
|
||||
type MinifiedData = {
|
||||
id: string;
|
||||
title: string;
|
||||
subTitle?: string;
|
||||
};
|
||||
type ItemsSelectionViewProps = {
|
||||
items: MinifiedData[] | [];
|
||||
fieldsItems: MinifiedData[] | [];
|
||||
selectedItemId?: string | null;
|
||||
setSelectedItem: (value: string | null) => void;
|
||||
setSelectedQuestion: (value: string | null) => void;
|
||||
selectedField?: string | null;
|
||||
setSelectedField: (value: string | null) => void;
|
||||
handleScroll?: () => void;
|
||||
onLargeBtnClick: () => void;
|
||||
onSmallBtnClick: () => void;
|
||||
activeScope: TagKeys;
|
||||
};
|
||||
FieldsAllowedFC: MinifiedData[];
|
||||
setIsCurrentFields: (a:boolean) => void;
|
||||
isCurrentFields: boolean
|
||||
}
|
||||
export const EntitiesQuestions: FC<ItemsSelectionViewProps> = ({
|
||||
items,
|
||||
fieldsItems,
|
||||
selectedItemId,
|
||||
setSelectedItem,
|
||||
setSelectedQuestion,
|
||||
selectedField,
|
||||
setSelectedField,
|
||||
handleScroll,
|
||||
onLargeBtnClick,
|
||||
onSmallBtnClick,
|
||||
activeScope,
|
||||
FieldsAllowedFC,
|
||||
setIsCurrentFields,
|
||||
isCurrentFields,
|
||||
}) => {
|
||||
|
||||
|
||||
const [isCurrentFields, setIsCurrentFields] = useState(true);
|
||||
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
@ -77,9 +82,20 @@ export const EntitiesQuestions: FC<ItemsSelectionViewProps> = ({
|
||||
</Box>
|
||||
{
|
||||
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
|
||||
@ -89,7 +105,9 @@ export const EntitiesQuestions: FC<ItemsSelectionViewProps> = ({
|
||||
}}
|
||||
>
|
||||
<StepButtonsBlock
|
||||
onLargeBtnClick={onLargeBtnClick}
|
||||
onLargeBtnClick={() => {
|
||||
onLargeBtnClick()
|
||||
}}
|
||||
largeBtnText={"Добавить"}
|
||||
onSmallBtnClick={onSmallBtnClick}
|
||||
smallBtnText={"Отменить"}
|
||||
|
||||
@ -25,6 +25,7 @@ export const ItemDetailsView: FC<ItemDetailsViewProps> = ({
|
||||
setActiveScope,
|
||||
deleteHC,
|
||||
}) => {
|
||||
console.log(selectedQuestions)
|
||||
const theme = useTheme();
|
||||
|
||||
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 { StepButtonsBlock } from "../../StepButtonsBlock/StepButtonsBlock";
|
||||
import { FC } from "react";
|
||||
import { TagKeys } from "../../types";
|
||||
import { MinifiedData, TagKeys } from "../../types";
|
||||
|
||||
type MinifiedData = {
|
||||
id: string;
|
||||
title: string;
|
||||
subTitle?: string;
|
||||
};
|
||||
type ItemsSelectionViewProps = {
|
||||
items: MinifiedData[] | [];
|
||||
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 = () => {
|
||||
return <>новые поля</>
|
||||
interface Props {
|
||||
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 QuestionKeys = "Company" | "Lead" | "Customer";
|
||||
export type QuestionKeys = "Company" | "Lead" | "Customer" | "Contact";
|
||||
export type SelectedQuestions = Record<QuestionKeys, string[]>;
|
||||
|
||||
export type MinifiedData = {
|
||||
|
||||
@ -10,17 +10,27 @@ import {
|
||||
getUsers,
|
||||
getAccount,
|
||||
FieldsRule,
|
||||
getFields,
|
||||
} from "@/api/integration";
|
||||
import { AnyTypedQuizQuestion } from "@frontend/squzanswerer";
|
||||
|
||||
const SIZE = 75;
|
||||
const SIZE = 175;
|
||||
|
||||
interface Props {
|
||||
isModalOpen: boolean;
|
||||
isTryRemoveAccount: boolean;
|
||||
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 [firstRules, setFirstRules] = useState<boolean>(false);
|
||||
const [accountInfo, setAccountInfo] = useState<AccountResponse | null>(null);
|
||||
@ -29,10 +39,12 @@ export const useAmoIntegration = ({ isModalOpen, isTryRemoveAccount, quizID }: P
|
||||
const [arrayOfPipelinesSteps, setArrayOfPipelinesSteps] = useState<MinifiedData[]>([]);
|
||||
const [arrayOfUsers, setArrayOfUsers] = useState<MinifiedData[]>([]);
|
||||
const [arrayOfTags, setArrayOfTags] = useState<MinifiedData[]>([]);
|
||||
const [arrayOfFields, setArrayOfFields] = useState<MinifiedData[]>([]);
|
||||
|
||||
const [selectedPipeline, setSelectedPipeline] = useState<string | null>(null);
|
||||
const [selectedPipelineStep, setSelectedPipelineStep] = useState<string | null>(null);
|
||||
const [selectedDealUser, setSelectedDealPerformer] = useState<string | null>(null);
|
||||
const [selectedCurrentFields, setSelectedCurrentFields] = useState<MinifiedData[]>([]);
|
||||
|
||||
const [questionsBackend, setQuestionsBackend] = useState<FieldsRule>({} as FieldsRule);
|
||||
const [selectedTags, setSelectedTags] = useState<SelectedTags>({
|
||||
@ -45,15 +57,16 @@ export const useAmoIntegration = ({ isModalOpen, isTryRemoveAccount, quizID }: P
|
||||
Lead: [],
|
||||
Company: [],
|
||||
Customer: [],
|
||||
Contact: []
|
||||
});
|
||||
|
||||
const [pageOfPipelines, setPageOfPipelines] = useState(1);
|
||||
const [pageOfPipelinesSteps, setPageOfPipelinesSteps] = useState(1);
|
||||
const [pageOfUsers, setPageOfUsers] = useState(1);
|
||||
const [pageOfTags, setPageOfTags] = useState(1);
|
||||
const [pageOfFields, setPageOfFields] = useState(1);
|
||||
|
||||
useEffect(() => {
|
||||
if (isModalOpen && !isTryRemoveAccount) {
|
||||
const fetchAccountRules = async () => {
|
||||
setIsLoadingPage(true);
|
||||
const [account, accountError] = await getAccount();
|
||||
@ -82,12 +95,27 @@ export const useAmoIntegration = ({ isModalOpen, isTryRemoveAccount, quizID }: P
|
||||
|
||||
for (let key in settingsResponse.FieldsRule) {
|
||||
if (
|
||||
settingsResponse.FieldsRule[key as QuestionKeys] !== null &&
|
||||
Array.isArray(settingsResponse.FieldsRule[key as QuestionKeys])
|
||||
settingsResponse.FieldsRule[key as QuestionKeys] !== null
|
||||
) {
|
||||
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);
|
||||
@ -110,32 +138,7 @@ export const useAmoIntegration = ({ isModalOpen, isTryRemoveAccount, quizID }: P
|
||||
};
|
||||
|
||||
fetchAccountRules();
|
||||
} else {
|
||||
//Вот по-хорошему компонент должен размонтироваться и стереть всё. Но это будет сделано позже
|
||||
setArrayOfPipelines([]);
|
||||
setArrayOfPipelinesSteps([]);
|
||||
setArrayOfUsers([]);
|
||||
setArrayOfTags([]);
|
||||
setSelectedPipeline(null);
|
||||
setSelectedPipelineStep(null);
|
||||
setSelectedDealPerformer(null);
|
||||
setQuestionsBackend({} as FieldsRule);
|
||||
setSelectedTags({
|
||||
Lead: [],
|
||||
Contact: [],
|
||||
Company: [],
|
||||
Customer: [],
|
||||
});
|
||||
setSelectedQuestions({
|
||||
Lead: [],
|
||||
Company: [],
|
||||
Customer: [],
|
||||
});
|
||||
setPageOfPipelines(1);
|
||||
setPageOfPipelinesSteps(1);
|
||||
setPageOfUsers(1);
|
||||
setPageOfTags(1);
|
||||
}
|
||||
|
||||
}, [isModalOpen, isTryRemoveAccount]);
|
||||
|
||||
useEffect(() => {
|
||||
@ -222,6 +225,32 @@ export const useAmoIntegration = ({ isModalOpen, isTryRemoveAccount, quizID }: P
|
||||
}
|
||||
});
|
||||
}, [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 {
|
||||
isLoadingPage,
|
||||
@ -231,8 +260,10 @@ export const useAmoIntegration = ({ isModalOpen, isTryRemoveAccount, quizID }: P
|
||||
arrayOfPipelinesSteps,
|
||||
arrayOfUsers,
|
||||
arrayOfTags,
|
||||
arrayOfFields,
|
||||
selectedPipeline,
|
||||
setSelectedPipeline,
|
||||
selectedCurrentFields,
|
||||
selectedPipelineStep,
|
||||
setSelectedPipelineStep,
|
||||
selectedDealUser,
|
||||
@ -246,5 +277,6 @@ export const useAmoIntegration = ({ isModalOpen, isTryRemoveAccount, quizID }: P
|
||||
setPageOfPipelinesSteps,
|
||||
setPageOfUsers,
|
||||
setPageOfTags,
|
||||
setSelectedCurrentFields,
|
||||
};
|
||||
};
|
||||
|
||||
@ -128,7 +128,7 @@ export const PartnersBoard: FC<PartnersBoardProps> = ({
|
||||
isModalOpen={isAmoCrmModalOpen}
|
||||
handleCloseModal={handleCloseAmoSRMModal}
|
||||
companyName={companyName}
|
||||
quizID={quiz?.backendId}
|
||||
quiz={quiz}
|
||||
/>
|
||||
</Suspense>
|
||||
)}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user