Merge branch 'dev' into 'staging'
Dev See merge request frontend/squiz!341
This commit is contained in:
commit
80dd693ea9
@ -239,10 +239,10 @@ export type IntegrationRules = {
|
||||
StepID: number;
|
||||
UTMs: number[];
|
||||
FieldsRule: {
|
||||
lead: { QuestionID: number }[];
|
||||
contact: { ContactRuleMap: string }[];
|
||||
company: { QuestionID: number }[];
|
||||
customer: { QuestionID: number }[];
|
||||
Lead: { QuestionID: number }[];
|
||||
Contact: { ContactRuleMap: string }[];
|
||||
Company: { QuestionID: number }[];
|
||||
Customer: { QuestionID: number }[];
|
||||
};
|
||||
Deleted: boolean;
|
||||
CreatedAt: number;
|
||||
@ -258,6 +258,7 @@ export const getIntegrationRules = async (
|
||||
});
|
||||
return [settingsResponse || null];
|
||||
} catch (nativeError) {
|
||||
if (nativeError.response.status === 404) return [null, "first"];
|
||||
const [error] = parseAxiosError(nativeError);
|
||||
return [null, `Не удалось получить настройки интеграции. ${error}`];
|
||||
}
|
||||
@ -278,6 +279,22 @@ export type IntegrationRulesUpdate = {
|
||||
};
|
||||
};
|
||||
|
||||
export const setIntegrationRules = async (
|
||||
quizID: string,
|
||||
settings: IntegrationRulesUpdate,
|
||||
): Promise<[string | null, string?]> => {
|
||||
try {
|
||||
const updateResponse = await makeRequest<IntegrationRulesUpdate, string>({
|
||||
method: "POST",
|
||||
url: `${API_URL}/rules/${quizID}`,
|
||||
body: settings,
|
||||
});
|
||||
return [updateResponse];
|
||||
} catch (nativeError) {
|
||||
const [error] = parseAxiosError(nativeError);
|
||||
return [null, `Failed to update integration settings. ${error}`];
|
||||
}
|
||||
};
|
||||
export const updateIntegrationRules = async (
|
||||
quizID: string,
|
||||
settings: IntegrationRulesUpdate,
|
||||
|
@ -139,11 +139,11 @@ export const CustomRadioGroup: FC<CustomRadioGroupProps> = ({
|
||||
borderRadius: "12px",
|
||||
margin: 0,
|
||||
backgroundColor:
|
||||
currentValue === item.AmoID.toString()
|
||||
currentValue === Number(item.AmoID)
|
||||
? theme.palette.background.default
|
||||
: theme.palette.common.white,
|
||||
}}
|
||||
value={item.AmoID.toString()}
|
||||
value={Number(item.AmoID)}
|
||||
control={
|
||||
<Radio
|
||||
checkedIcon={
|
||||
@ -185,7 +185,7 @@ export const CustomRadioGroup: FC<CustomRadioGroupProps> = ({
|
||||
? theme.palette.background.default
|
||||
: theme.palette.common.white,
|
||||
}}
|
||||
value={step.Name}
|
||||
value={step.AmoID}
|
||||
control={
|
||||
<Radio
|
||||
checkedIcon={
|
||||
@ -256,7 +256,7 @@ export const CustomRadioGroup: FC<CustomRadioGroupProps> = ({
|
||||
borderRadius: "12px",
|
||||
margin: 0,
|
||||
backgroundColor:
|
||||
currentValue === backendId
|
||||
currentValue === Number(backendId)
|
||||
? theme.palette.background.default
|
||||
: theme.palette.common.white,
|
||||
"&.MuiFormControlLabel-root > .MuiTypography-root": {
|
||||
@ -265,7 +265,7 @@ export const CustomRadioGroup: FC<CustomRadioGroupProps> = ({
|
||||
textOverflow: "ellipsis"
|
||||
}
|
||||
}}
|
||||
value={backendId}
|
||||
value={Number(backendId)}
|
||||
control={
|
||||
<Radio
|
||||
checkedIcon={
|
||||
@ -314,7 +314,12 @@ export const CustomRadioGroup: FC<CustomRadioGroupProps> = ({
|
||||
aria-labelledby="demo-controlled-radio-buttons-group"
|
||||
name="controlled-radio-buttons-group"
|
||||
value={currentValue}
|
||||
onChange={handleChange}
|
||||
onChange={(e) => {
|
||||
console.log("klick")
|
||||
console.log(e.target.value)
|
||||
console.log(typeof e.target.value)
|
||||
handleChange(e)
|
||||
}}
|
||||
>
|
||||
{formControlLabels}
|
||||
</RadioGroup>
|
||||
|
@ -95,7 +95,7 @@ export const CustomSelect: FC<CustomSelectProps> = ({
|
||||
return users.map((user) => (
|
||||
<MenuItem
|
||||
key={user.ID}
|
||||
value={user.Name}
|
||||
value={user.AmocrmID}
|
||||
sx={{
|
||||
padding: "6px 0",
|
||||
zIndex: 2,
|
||||
|
@ -18,18 +18,18 @@ import { AmoStep7 } from "./IntegrationStep7/AmoStep7";
|
||||
import { AmoModalTitle } from "./AmoModalTitle/AmoModalTitle";
|
||||
import { AmoSettingsBlock } from "./SettingsBlock/AmoSettingsBlock";
|
||||
import { AmoAccountInfo } from "./AmoAccountInfo/AmoAccountInfo";
|
||||
import { AccountResponse, IntegrationRules, getAccount, getIntegrationRules } from "@api/integration";
|
||||
import { AccountResponse, IntegrationRules, getAccount, getIntegrationRules, setIntegrationRules, updateIntegrationRules } from "@api/integration";
|
||||
import { useQuestions } from "@/stores/questions/hooks";
|
||||
import { redirect } from "react-router-dom";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
|
||||
export type TitleKeys = "contacts" | "company" | "deal" | "buyers";
|
||||
export type TitleKeys = "Contact" | "Company" | "Lead" | "Customer";
|
||||
export type TagQuestionObject = {
|
||||
backendId: string;
|
||||
title: string;
|
||||
};
|
||||
|
||||
export type TQuestionEntity = Record<TitleKeys, string[] | []>;
|
||||
export type TQuestionEntity = Record<TitleKeys, number[] | []>;
|
||||
type IntegrationsModalProps = {
|
||||
isModalOpen: boolean;
|
||||
handleCloseModal: () => void;
|
||||
@ -37,8 +37,8 @@ type IntegrationsModalProps = {
|
||||
quizID: number | undefined;
|
||||
};
|
||||
|
||||
export type TagKeys = "contact" | "company" | "deal" | "buyer";
|
||||
export type TTags = Record<TagKeys, string[] | []>;
|
||||
export type TagKeys = "Contact" | "Company" | "Lead" | "Customer";
|
||||
export type TTags = Record<TagKeys, number[] | []>;
|
||||
|
||||
export const AmoCRMModal: FC<IntegrationsModalProps> = ({
|
||||
isModalOpen,
|
||||
@ -56,8 +56,9 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({
|
||||
const [isSettingsBlock, setIsSettingsBlock] = useState<boolean>(false);
|
||||
const [isRemoveAccount, setIsRemoveAccount] = useState<boolean>(false);
|
||||
|
||||
const [firstRules, setFirstRules] = useState<boolean>(false);
|
||||
|
||||
const [accountInfo, setAccountInfo] = useState<AccountResponse | null>(null);
|
||||
const [integrationRules, setIntegrationRules] = useState<IntegrationRules | null>(null);
|
||||
const [selectedPipelinePerformer, setSelectedPipelinePerformer] = useState<
|
||||
string | null
|
||||
>(null);
|
||||
@ -70,16 +71,16 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({
|
||||
string | null
|
||||
>(null);
|
||||
const [questionEntity, setQuestionEntity] = useState<TQuestionEntity>({
|
||||
deal: [],
|
||||
contacts: [],
|
||||
company: [],
|
||||
buyers: [],
|
||||
Lead: [],
|
||||
Contact: [],
|
||||
Company: [],
|
||||
Customer: [],
|
||||
});
|
||||
const [tags, setTags] = useState<TTags>({
|
||||
deal: [],
|
||||
contact: [],
|
||||
company: [],
|
||||
buyer: [],
|
||||
Lead: [],
|
||||
Contact: [],
|
||||
Company: [],
|
||||
Customer: [],
|
||||
});
|
||||
console.log(questionEntity)
|
||||
console.log(tags)
|
||||
@ -101,12 +102,14 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({
|
||||
const [settingsResponse, error] = await getIntegrationRules(quizID.toString());
|
||||
|
||||
if (error) {
|
||||
if (!error.includes("Not Found")) enqueueSnackbar(error)
|
||||
setIntegrationRules(null);
|
||||
if (error === "first") setFirstRules(true);
|
||||
if (!error.includes("Not Found") && !error.includes("first")) enqueueSnackbar(error);
|
||||
}
|
||||
if (settingsResponse) {
|
||||
setIntegrationRules(settingsResponse);
|
||||
console.log(settingsResponse);
|
||||
setFirstRules(false);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
fetchAccount();
|
||||
@ -121,8 +124,53 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({
|
||||
setStep((prevState) => prevState - 1);
|
||||
};
|
||||
const handleSave = () => {
|
||||
handleCloseModal();
|
||||
setStep(1);
|
||||
console.log("На отправку")
|
||||
console.log({
|
||||
PerformerID: selectedDealPerformer,
|
||||
PipelineID: selectedPipeline,
|
||||
StepID: selectedStep,
|
||||
Fieldsrule: {
|
||||
...questionEntity
|
||||
},
|
||||
TagsToAdd: {
|
||||
...tags
|
||||
}
|
||||
})
|
||||
if (quizID === undefined) return
|
||||
if (selectedPipeline?.toString().length === 0) return enqueueSnackbar("Выберите воронку")
|
||||
if (selectedPipeline?.toString().length === 0) return enqueueSnackbar("Выберите этап воронки")
|
||||
|
||||
if (firstRules) {
|
||||
setIntegrationRules(quizID.toString(), {
|
||||
PerformerID: Number(selectedDealPerformer),
|
||||
PipelineID: Number(selectedPipeline),
|
||||
StepID: Number(selectedStep),
|
||||
Fieldsrule: {
|
||||
...questionEntity
|
||||
},
|
||||
TagsToAdd: {
|
||||
...tags
|
||||
}
|
||||
})
|
||||
} else {
|
||||
const body = {
|
||||
|
||||
Fieldsrule: {
|
||||
...questionEntity
|
||||
},
|
||||
TagsToAdd: {
|
||||
...tags
|
||||
}
|
||||
};
|
||||
if (selectedDealPerformer?.toString() > 0) body.PerformerID = Number(selectedDealPerformer)
|
||||
if (selectedPipeline?.toString() > 0) body.PipelineID = Number(selectedPipeline)
|
||||
if (selectedStep?.toString() > 0) body.StepID = Number(selectedStep)
|
||||
|
||||
updateIntegrationRules(quizID.toString(), body)
|
||||
}
|
||||
|
||||
// handleCloseModal();
|
||||
// setStep(1);
|
||||
};
|
||||
const steps = useMemo(
|
||||
() => [
|
||||
@ -147,8 +195,9 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({
|
||||
<AmoStep2
|
||||
handlePrevStep={handlePrevStep}
|
||||
handleNextStep={handleNextStep}
|
||||
selectedPipelinePerformer={selectedPipelinePerformer}
|
||||
setSelectedPipelinePerformer={setSelectedPipelinePerformer}
|
||||
selectedPipelinePerformer={selectedDealPerformer}
|
||||
setSelectedPipelinePerformer={setSelectedDealPerformer}
|
||||
setSelectedDealPerformer={setSelectedDealPerformer}
|
||||
selectedPipeline={selectedPipeline}
|
||||
setSelectedPipeline={setSelectedPipeline}
|
||||
/>
|
||||
@ -161,8 +210,8 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({
|
||||
<AmoStep3
|
||||
handlePrevStep={handlePrevStep}
|
||||
handleNextStep={handleNextStep}
|
||||
selectedStepsPerformer={selectedStepsPerformer}
|
||||
setSelectedStepsPerformer={setSelectedStepsPerformer}
|
||||
selectedStepsPerformer={selectedDealPerformer}
|
||||
setSelectedStepsPerformer={setSelectedDealPerformer}
|
||||
selectedStep={selectedStep}
|
||||
setSelectedStep={setSelectedStep}
|
||||
pipelineId={selectedPipeline}
|
||||
@ -186,7 +235,7 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({
|
||||
isSettingsAvailable: true,
|
||||
component: (
|
||||
<AmoStep6
|
||||
tagsNames={tags}
|
||||
tagsNames={tags}
|
||||
handlePrevStep={handlePrevStep}
|
||||
handleNextStep={handleNextStep}
|
||||
setTagsNames={setTags}
|
||||
@ -289,8 +338,8 @@ export const AmoCRMModal: FC<IntegrationsModalProps> = ({
|
||||
startRemoveAccount={() => setIsRemoveAccount(true)}
|
||||
/>
|
||||
{isRemoveAccount && (
|
||||
<AmoRemoveAccount
|
||||
stopThisPage={() => setIsRemoveAccount(false)}
|
||||
<AmoRemoveAccount
|
||||
stopThisPage={() => setIsRemoveAccount(false)}
|
||||
/>
|
||||
)}
|
||||
{isSettingsBlock && (
|
||||
|
@ -11,6 +11,7 @@ type AmoStep2Props = {
|
||||
setSelectedPipelinePerformer: (value: string | null) => void;
|
||||
selectedPipeline: string | null;
|
||||
setSelectedPipeline: (value: string | null) => void;
|
||||
|
||||
};
|
||||
|
||||
export const AmoStep2: FC<AmoStep2Props> = ({
|
||||
|
@ -38,7 +38,7 @@ export const AmoStep6: FC<Props> = ({
|
||||
|
||||
setTagsNames((prevState) => ({
|
||||
...prevState,
|
||||
[activeItem]: [...prevState[activeItem as TagKeys], selectedValue],
|
||||
[activeItem]: [...prevState[activeItem as TagKeys], Number(selectedValue)],
|
||||
}));
|
||||
}, [activeItem, setTagsNames, selectedValue]);
|
||||
|
||||
|
@ -40,7 +40,7 @@ export const AmoStep7: FC<Props> = ({
|
||||
|
||||
setQuestionEntity((prevState) => ({
|
||||
...prevState,
|
||||
[activeItem]: [...prevState[activeItem as TitleKeys], selectedValue],
|
||||
[activeItem]: [...prevState[activeItem as TitleKeys], Number(selectedValue)],
|
||||
}));
|
||||
}, [activeItem, setQuestionEntity, selectedValue]);
|
||||
|
||||
@ -50,7 +50,7 @@ export const AmoStep7: FC<Props> = ({
|
||||
type !== "result"
|
||||
&& type !== null)
|
||||
.map(({ backendId, title }) => ({
|
||||
backendId: backendId.toString(),
|
||||
backendId: backendId,
|
||||
title
|
||||
})),
|
||||
[],
|
||||
@ -59,7 +59,6 @@ export const AmoStep7: FC<Props> = ({
|
||||
const translated = {} as TQuestionEntity;
|
||||
|
||||
for (let key in questionEntity) {
|
||||
// /* ... делать что-то с obj[key] ... */
|
||||
translated[key] = questionEntity[key].map((id) =>
|
||||
questions.find((q) => q.backendId === Number(id))?.title || id
|
||||
)
|
||||
|
@ -15,13 +15,10 @@ export const Item: FC<ItemProps> = ({ title, onAddBtnClick, data }) => {
|
||||
console.log("title")
|
||||
console.log(data)
|
||||
const titleDictionary = {
|
||||
contact: "Контакт",
|
||||
company: "Компания",
|
||||
deal: "Сделка",
|
||||
buyer: "Покупатель",
|
||||
contacts: "Контакты",
|
||||
users: "Пользователи",
|
||||
buyers: "Покупатели",
|
||||
Company: "Компания",
|
||||
Lead: "Сделка",
|
||||
Contact: "Контакты",
|
||||
Customer: "Покупатели",
|
||||
};
|
||||
|
||||
const translatedTitle = titleDictionary[title];
|
||||
|
@ -4,7 +4,7 @@ import { StepButtonsBlock } from "../../StepButtonsBlock/StepButtonsBlock";
|
||||
import { FC } from "react";
|
||||
import { TQuestionEntity } from "../../AmoCRMModal";
|
||||
|
||||
type TitleKeys = "contacts" | "company" | "deal" | "buyers";
|
||||
type TitleKeys = "Contact" | "Company" | "Lead" | "Customer";
|
||||
|
||||
type ItemDetailsViewProps = {
|
||||
setIsSelection: (value: boolean) => void;
|
||||
|
Loading…
Reference in New Issue
Block a user