feat: rebase

This commit is contained in:
Mohamed Marrouchi 2024-11-27 20:12:09 +01:00
parent 1da3a3d9ba
commit 97146b98a5
3 changed files with 39 additions and 22 deletions

View File

@ -34,10 +34,10 @@ const getType = (pattern: Pattern): PatternType => {
return "regex"; return "regex";
} else if (Array.isArray(pattern)) { } else if (Array.isArray(pattern)) {
return "nlp"; return "nlp";
} else if (typeof pattern === "object" && pattern !== null) { } else if (typeof pattern === "object") {
if (pattern.type === "menu") { if (pattern?.type === "menu") {
return "menu"; return "menu";
} else if (pattern.type === "content") { } else if (pattern?.type === "content") {
return "content"; return "content";
} else { } else {
return "payload"; return "payload";

View File

@ -15,7 +15,7 @@ import {
Spellcheck, Spellcheck,
} from "@mui/icons-material"; } from "@mui/icons-material";
import { Box, IconButton, styled } from "@mui/material"; import { Box, IconButton, styled } from "@mui/material";
import { FC, useEffect, useState } from "react"; import { FC, useEffect, useMemo, useState } from "react";
import { useFormContext } from "react-hook-form"; import { useFormContext } from "react-hook-form";
import DropdownButton, { import DropdownButton, {
@ -23,6 +23,7 @@ import DropdownButton, {
} from "@/app-components/buttons/DropdownButton"; } from "@/app-components/buttons/DropdownButton";
import { useTranslate } from "@/hooks/useTranslate"; import { useTranslate } from "@/hooks/useTranslate";
import { Pattern } from "@/types/block.types"; import { Pattern } from "@/types/block.types";
import { PayloadType } from "@/types/message.types";
import { SXStyleOptions } from "@/utils/SXStyleOptions"; import { SXStyleOptions } from "@/utils/SXStyleOptions";
import { createValueWithId, ValueWithId } from "@/utils/valueWithId"; import { createValueWithId, ValueWithId } from "@/utils/valueWithId";
@ -39,12 +40,6 @@ const StyledNoPatternsDiv = styled("div")(
width: "100%", width: "100%",
}), }),
); );
const actions: DropdownButtonAction[] = [
{ icon: <Spellcheck />, name: "Exact Match", defaultValue: "" },
{ icon: <Abc />, name: "Pattern Match", defaultValue: "//" },
{ icon: <PsychologyAlt />, name: "Intent Match", defaultValue: [] },
{ icon: <Mouse />, name: "Interaction", defaultValue: {} },
];
type PatternsInputProps = { type PatternsInputProps = {
value: Pattern[]; value: Pattern[];
@ -78,8 +73,29 @@ const PatternsInput: FC<PatternsInputProps> = ({ value, onChange }) => {
useEffect(() => { useEffect(() => {
onChange(patterns.map(({ value }) => value)); onChange(patterns.map(({ value }) => value));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [patterns]); }, [patterns]);
const actions: DropdownButtonAction[] = useMemo(
() => [
{ icon: <Spellcheck />, name: "Exact Match", defaultValue: "" },
{ icon: <Abc />, name: "Pattern Match", defaultValue: "//" },
{ icon: <PsychologyAlt />, name: "Intent Match", defaultValue: [] },
{
icon: <Mouse />,
name: "Interaction",
defaultValue: {
label: t("label.get_started"),
value: "GET_STARTED",
type: PayloadType.button,
group: "general",
},
},
],
// eslint-disable-next-line react-hooks/exhaustive-deps
[],
);
return ( return (
<Box display="flex" flexDirection="column"> <Box display="flex" flexDirection="column">
<Box display="flex" flexDirection="column"> <Box display="flex" flexDirection="column">
@ -99,7 +115,11 @@ const PatternsInput: FC<PatternsInputProps> = ({ value, onChange }) => {
t("message.text_is_required"), t("message.text_is_required"),
)} )}
/> />
<IconButton size="small" color="error" onClick={() => removeInput(idx)}> <IconButton
size="small"
color="error"
onClick={() => removeInput(idx)}
>
<RemoveCircleOutline /> <RemoveCircleOutline />
</IconButton> </IconButton>
</Box> </Box>

View File

@ -44,8 +44,8 @@ const isSamePostback = <T extends PayloadPattern>(a: T, b: T) =>
a.label === b.label && a.value === b.value; a.label === b.label && a.value === b.value;
type PostbackInputProps = { type PostbackInputProps = {
defaultValue?: PayloadPattern; defaultValue: PayloadPattern;
onChange: (pattern: PayloadPattern | null) => void; onChange: (pattern: PayloadPattern) => void;
}; };
export const PostbackInput = ({ export const PostbackInput = ({
@ -53,7 +53,7 @@ export const PostbackInput = ({
onChange, onChange,
}: PostbackInputProps) => { }: PostbackInputProps) => {
const block = useBlock(); const block = useBlock();
const [selectedValue, setSelectedValue] = useState(defaultValue || null); const [selectedValue, setSelectedValue] = useState(defaultValue);
const getBlockFromCache = useGetFromCache(EntityType.BLOCK); const getBlockFromCache = useGetFromCache(EntityType.BLOCK);
const { data: menu, isLoading: isLoadingMenu } = useFind( const { data: menu, isLoading: isLoadingMenu } = useFind(
{ entity: EntityType.MENU, format: Format.FULL }, { entity: EntityType.MENU, format: Format.FULL },
@ -74,7 +74,6 @@ export const PostbackInput = ({
type: PayloadType.button, type: PayloadType.button,
group: "general", group: "general",
}, },
{ {
label: t("label.view_more"), label: t("label.view_more"),
value: "VIEW_MORE", value: "VIEW_MORE",
@ -212,19 +211,17 @@ export const PostbackInput = ({
return ( return (
<Autocomplete <Autocomplete
size="small" size="small"
defaultValue={selected} fullWidth
defaultValue={selected || undefined}
value={selected} value={selected}
options={options} options={options}
multiple={false} multiple={false}
disableClearable
onChange={(_e, value) => { onChange={(_e, value) => {
setSelectedValue(value); setSelectedValue(value);
if (value) { const { group: _g, ...payloadPattern } = value;
const { group: _g, ...payloadPattern } = value;
onChange(payloadPattern); onChange(payloadPattern);
} else {
onChange(null);
}
}} }}
groupBy={({ group }) => group ?? t("label.other")} groupBy={({ group }) => group ?? t("label.other")}
getOptionLabel={({ label }) => label} getOptionLabel={({ label }) => label}