feat(admin-ui): Metadata for stock locations (#3955)
* initial update to stock locations * add changeset
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/admin-ui": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Feat(admin-ui): add metadata controls for stock locations
|
||||||
@@ -4,19 +4,26 @@ import {
|
|||||||
StockLocationAddressInput,
|
StockLocationAddressInput,
|
||||||
StockLocationDTO,
|
StockLocationDTO,
|
||||||
} from "@medusajs/medusa"
|
} from "@medusajs/medusa"
|
||||||
import { useAdminUpdateStockLocation } from "medusa-react"
|
import GeneralForm, { GeneralFormType } from "../components/general-form"
|
||||||
import { useForm } from "react-hook-form"
|
import MetadataForm, {
|
||||||
|
MetadataFormType,
|
||||||
|
getMetadataFormValues,
|
||||||
|
getSubmittableMetadata,
|
||||||
|
} from "../../../../components/forms/general/metadata-form"
|
||||||
|
|
||||||
|
import AddressForm from "../components/address-form"
|
||||||
import Button from "../../../../components/fundamentals/button"
|
import Button from "../../../../components/fundamentals/button"
|
||||||
import Modal from "../../../../components/molecules/modal"
|
import Modal from "../../../../components/molecules/modal"
|
||||||
import useNotification from "../../../../hooks/use-notification"
|
|
||||||
import { getErrorMessage } from "../../../../utils/error-messages"
|
import { getErrorMessage } from "../../../../utils/error-messages"
|
||||||
import { nestedForm } from "../../../../utils/nested-form"
|
import { nestedForm } from "../../../../utils/nested-form"
|
||||||
import AddressForm from "../components/address-form"
|
import { useAdminUpdateStockLocation } from "medusa-react"
|
||||||
import GeneralForm, { GeneralFormType } from "../components/general-form"
|
import { useForm } from "react-hook-form"
|
||||||
|
import useNotification from "../../../../hooks/use-notification"
|
||||||
|
|
||||||
type EditLocationForm = {
|
type EditLocationForm = {
|
||||||
general: GeneralFormType
|
general: GeneralFormType
|
||||||
address: StockLocationAddressDTO
|
address: StockLocationAddressDTO
|
||||||
|
metadata: MetadataFormType
|
||||||
}
|
}
|
||||||
|
|
||||||
export type LocationEditModalProps = {
|
export type LocationEditModalProps = {
|
||||||
@@ -31,6 +38,7 @@ const LocationEditModal = ({ onClose, location }: LocationEditModalProps) => {
|
|||||||
name: location.name,
|
name: location.name,
|
||||||
}, // @ts-ignore
|
}, // @ts-ignore
|
||||||
address: location.address,
|
address: location.address,
|
||||||
|
metadata: getMetadataFormValues(location.metadata),
|
||||||
},
|
},
|
||||||
reValidateMode: "onBlur",
|
reValidateMode: "onBlur",
|
||||||
mode: "onBlur",
|
mode: "onBlur",
|
||||||
@@ -67,6 +75,10 @@ const LocationEditModal = ({ onClose, location }: LocationEditModalProps) => {
|
|||||||
<div className="mt-xlarge gap-y-xlarge flex flex-col">
|
<div className="mt-xlarge gap-y-xlarge flex flex-col">
|
||||||
<GeneralForm form={nestedForm(form, "general")} />
|
<GeneralForm form={nestedForm(form, "general")} />
|
||||||
<AddressForm form={nestedForm(form, "address")} />
|
<AddressForm form={nestedForm(form, "address")} />
|
||||||
|
<div>
|
||||||
|
<h2 className="inter-base-semibold mb-base">Metadata</h2>
|
||||||
|
<MetadataForm form={nestedForm(form, "metadata")} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</Modal.Content>
|
</Modal.Content>
|
||||||
@@ -97,7 +109,7 @@ const LocationEditModal = ({ onClose, location }: LocationEditModalProps) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const createPayload = (data): AdminPostStockLocationsReq => {
|
const createPayload = (data): AdminPostStockLocationsReq => {
|
||||||
const { general, address } = data
|
const { general, address, metadata } = data
|
||||||
|
|
||||||
let addressInput
|
let addressInput
|
||||||
if (address.address_1) {
|
if (address.address_1) {
|
||||||
@@ -113,6 +125,7 @@ const createPayload = (data): AdminPostStockLocationsReq => {
|
|||||||
return {
|
return {
|
||||||
name: general.name,
|
name: general.name,
|
||||||
address: addressInput,
|
address: addressInput,
|
||||||
|
metadata: getSubmittableMetadata(metadata),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import { AdminPostStockLocationsReq, SalesChannel } from "@medusajs/medusa"
|
import { AdminPostStockLocationsReq, SalesChannel } from "@medusajs/medusa"
|
||||||
import GeneralForm, { GeneralFormType } from "../components/general-form"
|
import GeneralForm, { GeneralFormType } from "../components/general-form"
|
||||||
|
import MetadataForm, {
|
||||||
|
MetadataFormType,
|
||||||
|
getSubmittableMetadata,
|
||||||
|
} from "../../../../components/forms/general/metadata-form"
|
||||||
import {
|
import {
|
||||||
StockLocationAddressDTO,
|
StockLocationAddressDTO,
|
||||||
StockLocationAddressInput,
|
StockLocationAddressInput,
|
||||||
@@ -27,6 +31,7 @@ import useToggleState from "../../../../hooks/use-toggle-state"
|
|||||||
type NewLocationForm = {
|
type NewLocationForm = {
|
||||||
general: GeneralFormType
|
general: GeneralFormType
|
||||||
address: StockLocationAddressDTO
|
address: StockLocationAddressDTO
|
||||||
|
metadata: MetadataFormType
|
||||||
salesChannels: {
|
salesChannels: {
|
||||||
channels: Omit<SalesChannel, "locations">[]
|
channels: Omit<SalesChannel, "locations">[]
|
||||||
}
|
}
|
||||||
@@ -179,6 +184,10 @@ const NewLocation = ({ onClose }: { onClose: () => void }) => {
|
|||||||
<div className="mt-xlarge gap-y-xlarge flex flex-col pb-0.5">
|
<div className="mt-xlarge gap-y-xlarge flex flex-col pb-0.5">
|
||||||
<GeneralForm form={nestedForm(form, "general")} />
|
<GeneralForm form={nestedForm(form, "general")} />
|
||||||
<AddressForm form={nestedForm(form, "address")} />
|
<AddressForm form={nestedForm(form, "address")} />
|
||||||
|
<div>
|
||||||
|
<h2 className="inter-base-semibold mb-base">Metadata</h2>
|
||||||
|
<MetadataForm form={nestedForm(form, "metadata")} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Accordion.Item>
|
</Accordion.Item>
|
||||||
{isFeatureEnabled("sales_channels") && (
|
{isFeatureEnabled("sales_channels") && (
|
||||||
@@ -212,7 +221,7 @@ const createPayload = (
|
|||||||
locationPayload: AdminPostStockLocationsReq
|
locationPayload: AdminPostStockLocationsReq
|
||||||
salesChannelsPayload: SalesChannel[]
|
salesChannelsPayload: SalesChannel[]
|
||||||
} => {
|
} => {
|
||||||
const { general, address } = data
|
const { general, address, metadata } = data
|
||||||
|
|
||||||
let addressInput
|
let addressInput
|
||||||
if (address.address_1) {
|
if (address.address_1) {
|
||||||
@@ -220,7 +229,11 @@ const createPayload = (
|
|||||||
addressInput.country_code = address.country_code.value
|
addressInput.country_code = address.country_code.value
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
locationPayload: { name: general.name, address: addressInput },
|
locationPayload: {
|
||||||
|
name: general.name,
|
||||||
|
address: addressInput,
|
||||||
|
metadata: getSubmittableMetadata(metadata),
|
||||||
|
},
|
||||||
salesChannelsPayload: data.salesChannels.channels,
|
salesChannelsPayload: data.salesChannels.channels,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user