Fix build errors
This commit is contained in:
parent
785d0965e3
commit
d0f1c1337c
28 changed files with 268 additions and 112 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { SelectInput } from "react-admin";
|
||||
|
||||
export const ProviderKindInput = (props) => (
|
||||
export const ProviderKindInput = (props: any) => (
|
||||
<SelectInput
|
||||
source="kind"
|
||||
choices={[{ id: "TWILIO", name: "Twilio" }]}
|
||||
|
|
|
|||
|
|
@ -10,13 +10,17 @@ import { useStopwatch } from "react-timer-hook";
|
|||
import style from "./MicInput.module.css";
|
||||
//import type { ReactMicProps } from "react-mic";
|
||||
|
||||
const ReactMic = dynamic<ReactMicProps>(
|
||||
const ReactMic = dynamic<any>(
|
||||
// eslint-disable-next-line promise/prefer-await-to-then
|
||||
() => { throw new Error("MIC INPUT FEATURE IS DISABLED"); /*return import("react-mic").then((mod) => mod.ReactMic);*/ } ,
|
||||
() => {
|
||||
throw new Error(
|
||||
"MIC INPUT FEATURE IS DISABLED"
|
||||
); /*return import("react-mic").then((mod) => mod.ReactMic);*/
|
||||
},
|
||||
{ ssr: false }
|
||||
);
|
||||
|
||||
const blobToDataUri = (blob) => {
|
||||
const blobToDataUri = (blob: Blob) => {
|
||||
const reader = new FileReader();
|
||||
reader.readAsDataURL(blob);
|
||||
return new Promise((resolve) => {
|
||||
|
|
@ -26,32 +30,32 @@ const blobToDataUri = (blob) => {
|
|||
});
|
||||
};
|
||||
|
||||
const dataUriToObj = (dataUri) => {
|
||||
const dataUriToObj = (dataUri: string) => {
|
||||
const [prefix, base64] = dataUri.split(",");
|
||||
const mime = prefix.slice(5, prefix.indexOf(";"));
|
||||
|
||||
const result = {};
|
||||
const result: any = {};
|
||||
result[mime] = base64;
|
||||
return result;
|
||||
};
|
||||
|
||||
const blobToResult = async (blob) => {
|
||||
const result = dataUriToObj(await blobToDataUri(blob));
|
||||
const blobToResult = async (blob: Blob) => {
|
||||
const result = dataUriToObj((await blobToDataUri(blob)) as string);
|
||||
return result;
|
||||
};
|
||||
|
||||
const resultToDataUri = (result): string => {
|
||||
const resultToDataUri = (result: Record<string, any>): string => {
|
||||
if (!result || !result["audio/webm"]) return "";
|
||||
const base64 = result["audio/webm"];
|
||||
const r = `data:audio/webm;base64,${base64}`;
|
||||
return r;
|
||||
};
|
||||
|
||||
const MicInput = (props) => {
|
||||
const MicInput = (props: any) => {
|
||||
const { seconds, minutes, hours, start, reset, pause } = useStopwatch();
|
||||
const theme = useTheme();
|
||||
const {
|
||||
input: { value, onChange },
|
||||
field: { value, onChange },
|
||||
} = useInput(props);
|
||||
|
||||
let [record, setRecorder] = useState({ record: false });
|
||||
|
|
@ -67,18 +71,16 @@ const MicInput = (props) => {
|
|||
pause();
|
||||
};
|
||||
|
||||
async function onData(recordedBlob) {}
|
||||
async function onData(recordedBlob: any) {}
|
||||
|
||||
async function onStop(recordedBlob) {
|
||||
async function onStop(recordedBlob: any) {
|
||||
const result = await blobToResult(recordedBlob.blob);
|
||||
onChange(result);
|
||||
}
|
||||
|
||||
const isRecording = record.record;
|
||||
const canPlay = !isRecording && decodedValue;
|
||||
const duration = `${hours
|
||||
.toString()
|
||||
.padStart(2, "0")}:${minutes
|
||||
const duration = `${hours.toString().padStart(2, "0")}:${minutes
|
||||
.toString()
|
||||
.padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ const VoiceLineList = (props: ListProps) => (
|
|||
source="providerId"
|
||||
reference="providers"
|
||||
>
|
||||
<FunctionField render={(p) => `${p.kind}: ${p.name}`} />
|
||||
<FunctionField render={(p: any) => `${p.kind}: ${p.name}`} />
|
||||
</ReferenceField>
|
||||
<TextField source="number" />
|
||||
<TextField source="language" />
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import TwilioLanguages from "./twilio-languages";
|
|||
|
||||
type TTSProvider = (voice: any, language: any, prompt: any) => Promise<void>;
|
||||
|
||||
const tts = async (providerId): Promise<TTSProvider> => {
|
||||
const tts = async (providerId: any): Promise<TTSProvider> => {
|
||||
const r = await fetch(
|
||||
`/api/v1/voice/twilio/text-to-speech-token/${providerId}`
|
||||
);
|
||||
|
|
@ -39,7 +39,7 @@ const tts = async (providerId): Promise<TTSProvider> => {
|
|||
outgoing: silence,
|
||||
},
|
||||
});
|
||||
device.on("ready", function (device) {
|
||||
device.on("ready", function (device: any) {
|
||||
device.connect({ language, voice, prompt });
|
||||
});
|
||||
device.on("disconnect", () => resolve());
|
||||
|
|
@ -47,7 +47,7 @@ const tts = async (providerId): Promise<TTSProvider> => {
|
|||
});
|
||||
};
|
||||
|
||||
export const TextToSpeechButton = ({ form }) => {
|
||||
export const TextToSpeechButton = ({ form }: any) => {
|
||||
const { providerId, language, voice, promptText: prompt } = form.formData;
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [ttsProvider, setTTSProvider] = useState<
|
||||
|
|
@ -90,7 +90,7 @@ export const TextToSpeechButton = ({ form }) => {
|
|||
);
|
||||
};
|
||||
|
||||
export const PromptInput = (form, ...rest) => {
|
||||
export const PromptInput = (form: any, ...rest: any[]) => {
|
||||
return (
|
||||
<TextInput
|
||||
source="promptText"
|
||||
|
|
@ -102,19 +102,23 @@ export const PromptInput = (form, ...rest) => {
|
|||
);
|
||||
};
|
||||
|
||||
const validateVoice = (args, values) => {
|
||||
const validateVoice = (args: any, values: any) => {
|
||||
if (!values.language) return "validation.language";
|
||||
if (!values.voice) return "validation.voice";
|
||||
|
||||
// @ts-expect-error
|
||||
const availableVoices = TwilioLanguages.voices[values.language];
|
||||
const found =
|
||||
availableVoices.filter((v) => v.id === values.voice).length === 1;
|
||||
availableVoices.filter((v: any) => v.id === values.voice).length === 1;
|
||||
if (!found) return "validation.voice";
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export const VoiceInput = (form, ...rest) => {
|
||||
export const VoiceInput = (form: any, ...rest: any[]) => {
|
||||
// @ts-expect-error
|
||||
const voice = TwilioLanguages.voices[form.formData.language] || [];
|
||||
return (
|
||||
// @ts-expect-error
|
||||
<SelectInput
|
||||
source="voice"
|
||||
choices={voice}
|
||||
|
|
@ -125,9 +129,9 @@ export const VoiceInput = (form, ...rest) => {
|
|||
};
|
||||
|
||||
let noAvailableNumbers = false;
|
||||
let availableNumbers = [];
|
||||
let availableNumbers: any[] = [];
|
||||
|
||||
const getAvailableNumbers = async (providerId) => {
|
||||
const getAvailableNumbers = async (providerId: string) => {
|
||||
try {
|
||||
const r = await fetch(`/api/v1/voice/providers/${providerId}/freeNumbers`);
|
||||
availableNumbers = await r.json();
|
||||
|
|
@ -141,24 +145,32 @@ const getAvailableNumbers = async (providerId) => {
|
|||
}
|
||||
};
|
||||
|
||||
const sidToNumber = (sid) => {
|
||||
const sidToNumber = (sid: any) => {
|
||||
return availableNumbers
|
||||
.filter(({ id }) => id === sid)
|
||||
.map(({ name }) => name)[0];
|
||||
};
|
||||
|
||||
export const populateNumber = (data) => {
|
||||
export const populateNumber = (data: any) => {
|
||||
return {
|
||||
...data,
|
||||
number: sidToNumber(data.providerLineSid),
|
||||
};
|
||||
};
|
||||
|
||||
const hasNumbers = (args, value, values, translate, ...props) => {
|
||||
const hasNumbers = (
|
||||
args: any,
|
||||
value: any,
|
||||
values: any,
|
||||
translate: any,
|
||||
...props: any[]
|
||||
) => {
|
||||
if (noAvailableNumbers) return "validation.noAvailableNumbers";
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export const AvailableNumbersInput = (form, ...rest) => {
|
||||
export const AvailableNumbersInput = (form: any, ...rest: any[]) => {
|
||||
const {
|
||||
// @ts-expect-error: non-existent property
|
||||
meta: { touched, error } = {},
|
||||
|
|
@ -181,7 +193,8 @@ export const AvailableNumbersInput = (form, ...rest) => {
|
|||
? translate("validation.noAvailableNumbers")
|
||||
: "",
|
||||
});
|
||||
if (noAvailableNumbers) notify("validation.noAvailableNumbers", "error");
|
||||
if (noAvailableNumbers)
|
||||
notify("validation.noAvailableNumbers", { type: "error" });
|
||||
setLoading(false);
|
||||
}
|
||||
}, [form && form.formData ? form.formData.providerId : undefined]);
|
||||
|
|
@ -278,19 +291,21 @@ export const AsyncSelectInput = (choiceLoader: () => Promise<any[]>, label, sour
|
|||
export const VoiceLineSelectInput = AsyncSelectInput(getVoiceLineChoices, "Voice Line", "backendId", "validation.noVoiceLines" )
|
||||
*/
|
||||
|
||||
export const VoiceLineSelectInput = (source: string) => () => (
|
||||
<ReferenceInput
|
||||
label="Voice Line"
|
||||
source={source}
|
||||
reference="voiceLines"
|
||||
validate={[required()]}
|
||||
>
|
||||
<SelectInput optionText="number" />
|
||||
</ReferenceInput>
|
||||
);
|
||||
export const VoiceLineSelectInput = (source: string) => () =>
|
||||
(
|
||||
<ReferenceInput
|
||||
label="Voice Line"
|
||||
source={source}
|
||||
reference="voiceLines"
|
||||
validate={[required()]}
|
||||
>
|
||||
<SelectInput optionText="number" />
|
||||
</ReferenceInput>
|
||||
);
|
||||
|
||||
export const VoiceLineField = (source: string) => () => (
|
||||
<ReferenceField label="Voice Line" source={source} reference="voiceLines">
|
||||
<TextField source="number" />
|
||||
</ReferenceField>
|
||||
);
|
||||
export const VoiceLineField = (source: string) => () =>
|
||||
(
|
||||
<ReferenceField label="Voice Line" source={source} reference="voiceLines">
|
||||
<TextField source="number" />
|
||||
</ReferenceField>
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue