2023-02-13 12:41:30 +00:00
|
|
|
import { SelectInput, required } from "react-admin";
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
VoiceLineField,
|
|
|
|
|
VoiceLineSelectInput,
|
|
|
|
|
} from "../voice/voicelines/shared";
|
|
|
|
|
import {
|
|
|
|
|
WhatsAppBotField,
|
|
|
|
|
WhatsAppBotSelectInput,
|
|
|
|
|
} from "../whatsapp/bots/shared";
|
|
|
|
|
import { SignalBotField, SignalBotSelectInput } from "../signal/bots/shared";
|
|
|
|
|
|
|
|
|
|
const httpChoices = [
|
|
|
|
|
{ id: "post", name: "POST" },
|
|
|
|
|
{ id: "put", name: "PUT" },
|
|
|
|
|
];
|
2023-03-14 17:40:24 +00:00
|
|
|
export const HttpMethodInput = (props: any) => (
|
2023-02-13 12:41:30 +00:00
|
|
|
<SelectInput
|
|
|
|
|
source="httpMethod"
|
|
|
|
|
choices={httpChoices}
|
|
|
|
|
validate={[required()]}
|
|
|
|
|
initialValue="post"
|
|
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const backendChoices = [
|
|
|
|
|
{ id: "signal", name: "Signal" },
|
|
|
|
|
{ id: "whatsapp", name: "WhatsApp" },
|
|
|
|
|
{ id: "voice", name: "Voice" },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const backendInputComponents = {
|
|
|
|
|
whatsapp: WhatsAppBotSelectInput("backendId"),
|
|
|
|
|
signal: SignalBotSelectInput("backendId"),
|
|
|
|
|
voice: VoiceLineSelectInput("backendId"),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const backendFieldComponents = {
|
|
|
|
|
whatsapp: WhatsAppBotField("backendId"),
|
|
|
|
|
signal: SignalBotField("backendId"),
|
|
|
|
|
voice: VoiceLineField("backendId"),
|
|
|
|
|
};
|
|
|
|
|
|
2023-03-14 17:40:24 +00:00
|
|
|
export const BackendTypeInput = (props: any) => (
|
2023-02-13 12:41:30 +00:00
|
|
|
<SelectInput
|
|
|
|
|
source="backendType"
|
|
|
|
|
choices={backendChoices}
|
|
|
|
|
validate={[required()]}
|
|
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
2023-03-14 17:40:24 +00:00
|
|
|
export const BackendIdInput = (form: any, ...rest: any[]) => {
|
2023-02-13 12:41:30 +00:00
|
|
|
const Component = form.formData.backendType
|
2023-03-14 17:40:24 +00:00
|
|
|
? // @ts-expect-error
|
|
|
|
|
backendInputComponents[form.formData.backendType]
|
2023-02-13 12:41:30 +00:00
|
|
|
: false;
|
|
|
|
|
return <>{Component && <Component form={form} {...rest} />}</>;
|
|
|
|
|
};
|
|
|
|
|
|
2023-03-14 17:40:24 +00:00
|
|
|
export const BackendIdField = (form: any, ...rest: any[]) => {
|
2023-02-13 12:41:30 +00:00
|
|
|
console.log(form);
|
|
|
|
|
|
|
|
|
|
const Component = form.record.backendType
|
2023-03-14 17:40:24 +00:00
|
|
|
? // @ts-expect-error
|
|
|
|
|
backendFieldComponents[form.record.backendType]
|
2023-02-13 12:41:30 +00:00
|
|
|
: false;
|
|
|
|
|
return <>{Component && <Component form={form} {...rest} />}</>;
|
|
|
|
|
};
|