fix: code syntax

This commit is contained in:
yassinedorbozgithub 2024-11-27 14:48:28 +01:00
parent 2a3290be4b
commit 8ac62d796f
2 changed files with 7 additions and 14 deletions

View File

@ -23,7 +23,7 @@ import {
PayloadPattern, PayloadPattern,
} from "@/types/block.types"; } from "@/types/block.types";
import { PostbackInputV2 } from "./PostbackInputV2"; import { PostbackInput } from "./PostbackInput";
const isRegex = (str: Pattern) => { const isRegex = (str: Pattern) => {
return typeof str === "string" && str.startsWith("/") && str.endsWith("/"); return typeof str === "string" && str.startsWith("/") && str.endsWith("/");
@ -150,7 +150,7 @@ const PatternInput: FC<PatternInputProps> = ({
/> />
)} )}
{["payload", "content", "menu"].includes(patternType) ? ( {["payload", "content", "menu"].includes(patternType) ? (
<PostbackInputV2 <PostbackInput
onChange={(payload) => { onChange={(payload) => {
payload && setPattern(payload); payload && setPattern(payload);
}} }}

View File

@ -30,18 +30,12 @@ type PayloadOption = {
group?: string; group?: string;
}; };
type ContentPayloadOption = {
id: string;
label: string;
group?: string;
};
type PostbackInputProps = { type PostbackInputProps = {
value?: string | null; value?: string | null;
onChange: (pattern: PayloadPattern) => void; onChange: (pattern: PayloadPattern) => void;
}; };
export const PostbackInputV2 = ({ value, onChange }: PostbackInputProps) => { export const PostbackInput = ({ value, onChange }: PostbackInputProps) => {
const block = useBlock(); const block = useBlock();
const getBlockFromCache = useGetFromCache(EntityType.BLOCK); const getBlockFromCache = useGetFromCache(EntityType.BLOCK);
const { data: menu } = useFind( const { data: menu } = useFind(
@ -176,7 +170,7 @@ export const PostbackInputV2 = ({ value, onChange }: PostbackInputProps) => {
return acc; return acc;
}, payloads); }, payloads);
}, [] as ContentPayloadOption[]); }, [] as PayloadOption[]);
}) })
.flat(), .flat(),
[block?.previousBlocks, contents, getBlockFromCache], [block?.previousBlocks, contents, getBlockFromCache],
@ -189,9 +183,9 @@ export const PostbackInputV2 = ({ value, onChange }: PostbackInputProps) => {
...menuOptions, ...menuOptions,
...contentOptions, ...contentOptions,
]; ];
const existOption = options.find((e) => e.id === value); const isOptionsReady = options.find((e) => e.id === value);
if (!existOption) { if (!isOptionsReady) {
return ( return (
<Skeleton animation="wave" variant="rounded" width="100%" height={40} /> <Skeleton animation="wave" variant="rounded" width="100%" height={40} />
); );
@ -206,7 +200,7 @@ export const PostbackInputV2 = ({ value, onChange }: PostbackInputProps) => {
label={t("label.postback")} label={t("label.postback")}
multiple={false} multiple={false}
onChange={(_e, content) => { onChange={(_e, content) => {
if (content) { content &&
onChange({ onChange({
label: content.label, label: content.label,
value: content.id, value: content.id,
@ -214,7 +208,6 @@ export const PostbackInputV2 = ({ value, onChange }: PostbackInputProps) => {
? content.group ? content.group
: undefined, : undefined,
} as PayloadPattern); } as PayloadPattern);
}
}} }}
groupBy={(option) => { groupBy={(option) => {
return option.group ?? t("label.other"); return option.group ?? t("label.other");