import { useIsAnyActionRunning, useLanguageProfiles } from "@/apis/hooks"; import { useModal, useModalControl, usePayload, withModal, } from "@/modules/modals"; import { GetItemId } from "@/utilities"; import { FunctionComponent, useMemo, useState } from "react"; import { Container, Form } from "react-bootstrap"; import { UseMutationResult } from "react-query"; import { AsyncButton, Selector, SelectorOption } from ".."; interface Props { mutation: UseMutationResult; } const Editor: FunctionComponent = ({ mutation }) => { const { data: profiles } = useLanguageProfiles(); const payload = usePayload(); const { mutateAsync, isLoading } = mutation; const { hide } = useModalControl(); const hasTask = useIsAnyActionRunning(); const profileOptions = useMemo[]>( () => profiles?.map((v) => { return { label: v.name, value: v.profileId }; }) ?? [], [profiles] ); const [id, setId] = useState>(payload?.profileId ?? null); const Modal = useModal({ closeable: !isLoading, onMounted: () => { setId(payload?.profileId ?? null); }, }); const footer = ( { if (payload) { const itemId = GetItemId(payload); if (!itemId) { return null; } return mutateAsync({ id: [itemId], profileid: [id], }); } else { return null; } }} onSuccess={() => hide()} > Save ); return (
Audio v.name) .join(", ")} > Languages Profiles setId(v === undefined ? null : v)} >
); }; export default withModal(Editor, "edit");