import { SalesChannel, StockLocationExpandedDTO } from "@medusajs/medusa" import { useFieldArray } from "react-hook-form" import { useTranslation } from "react-i18next" import SalesChannelsModal from "../../../../../components/forms/product/sales-channels-modal" import Button from "../../../../../components/fundamentals/button" import SalesChannelsList from "../../../../../components/molecules/sales-channels-list" import useToggleState from "../../../../../hooks/use-toggle-state" import { NestedForm } from "../../../../../utils/nested-form" import { AddSalesChannelsFormType } from "../../../../products/new/add-sales-channels" const SalesChannelsForm = ({ location, form, }: { location: StockLocationExpandedDTO | null form: NestedForm }) => { const { t } = useTranslation() const { state: showSalesChannelsModal, close: closeSalesChannelsModal, open: openSalesChannelsModal, } = useToggleState() const { control, path } = form const { fields, replace } = useFieldArray({ control, name: path("channels"), keyName: "fieldId", }) const onClose = () => { closeSalesChannelsModal() } const onChannelsSave = (channels: SalesChannel[]) => replace(channels) return ( <> {!location?.sales_channels && !fields.length ? ( ) : (
)} ) } export default SalesChannelsForm