Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(admin-ui): Inventory and order UI fixes and tweaks #3461

Merged
merged 9 commits into from
Mar 14, 2023
5 changes: 5 additions & 0 deletions .changeset/brown-wombats-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/admin-ui": patch
---

fix(admin-ui): Inventory and order UI fixes and tweaks
21 changes: 19 additions & 2 deletions packages/admin-ui/ui/src/components/molecules/table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type TableRowProps = React.HTMLAttributes<HTMLTableRowElement> & {
forceDropdown?: boolean
actions?: ActionType[]
linkTo?: string
clickable?: boolean
}

type TableCellProps = React.TdHTMLAttributes<HTMLTableCellElement> & {
Expand All @@ -28,6 +29,7 @@ export type TableProps = {
filteringOptions?: FilteringOptionProps[] | React.ReactNode
tableActions?: React.ReactNode
enableSearch?: boolean
searchClassName?: string
immediateSearchFocus?: boolean
searchPlaceholder?: string
searchValue?: string
Expand Down Expand Up @@ -55,6 +57,7 @@ const Table = React.forwardRef<HTMLTableElement, TableProps>(
children,
tableActions,
enableSearch,
searchClassName,
immediateSearchFocus,
searchPlaceholder,
searchValue,
Expand Down Expand Up @@ -89,6 +92,7 @@ const Table = React.forwardRef<HTMLTableElement, TableProps>(
placeholder={searchPlaceholder}
searchValue={searchValue}
onSearch={handleSearch!}
className={searchClassName}
/>
)}
</div>
Expand Down Expand Up @@ -217,15 +221,28 @@ Table.Cell = React.forwardRef<HTMLTableCellElement, TableCellProps>(
)

Table.Row = React.forwardRef<HTMLTableRowElement, TableRowProps>(
({ className, actions, children, linkTo, forceDropdown, ...props }, ref) => {
(
{
className,
actions,
children,
linkTo,
forceDropdown,
clickable,
...props
},
ref
) => {
const navigate = useNavigate()
return (
<tr
ref={ref}
className={clsx(
"inter-small-regular border-grey-20 text-grey-90 border-t border-b",
className,
{ "hover:bg-grey-5 cursor-pointer": linkTo !== undefined }
{
"hover:bg-grey-5 cursor-pointer": linkTo !== undefined || clickable,
}
)}
{...props}
{...(linkTo && {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import Button from "../../fundamentals/button"
import ImagePlaceholder from "../../fundamentals/image-placeholder"
import InputField from "../../molecules/input"
import InputHeader from "../../fundamentals/input-header"
import InventoryFilter from "../../../domain/inventory/filter-dropdown"
import Modal from "../../molecules/modal"
import { NextSelect } from "../../molecules/select/next-select"
import Spinner from "../../atoms/spinner"
Expand All @@ -28,7 +27,7 @@ import { isEmpty } from "lodash"
import qs from "qs"
import { useInventoryFilters } from "./use-inventory-filters"
import useInventoryTableColumn from "./use-inventory-column"
import { useLocation } from "react-router-dom"
import { useLocation, useNavigate } from "react-router-dom"
import useNotification from "../../../hooks/use-notification"
import useToggleState from "../../../hooks/use-toggle-state"

Expand Down Expand Up @@ -237,19 +236,8 @@ const InventoryTable: React.FC<InventoryTableProps> = () => {
isLoading={isLoading}
>
<Table
filteringOptions={
<InventoryFilter
filters={filters}
submitFilters={setFilters}
clearFilters={clearFilters}
tabs={filterTabs}
onTabClick={setTab}
activeTab={activeFilterTab}
onRemoveTab={removeTab}
onSaveTab={saveTab}
/>
}
enableSearch
searchClassName="h-[40px]"
handleSearch={setQuery}
searchValue={query}
tableActions={
Expand Down Expand Up @@ -313,16 +301,46 @@ const InventoryRow = ({
} & TableRowProps) => {
const inventory = row.original

const navigate = useNavigate()

const {
state: isShowingAdjustAvailabilityModal,
open: showAdjustAvailabilityModal,
close: closeAdjustAvailabilityModal,
} = useToggleState()

const getRowActionables = () => {
const productId = inventory.variants?.length
? inventory.variants[0].product_id
: null

const actions = [
{
label: "Adjust Availability",
onClick: showAdjustAvailabilityModal,
},
]

if (productId) {
return [
{
label: "View Product",
onClick: () => navigate(`/a/products/${productId}`),
},
...actions,
]
}

return actions
}

return (
<Table.Row
color={"inherit"}
onClick={showAdjustAvailabilityModal}
clickable
forceDropdown
actions={getRowActionables()}
{...rest}
>
{row.cells.map((cell: Cell, index: number) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,15 @@ const EditAllocationDrawer = ({
const handleDelete = () => {
deleteReservation(undefined, {
onSuccess: () => {
notification("Success", "Allocation deleted successfully", "success")
notification(
"Allocation was deleted",
"The allocated items have been released.",
"success"
)
close()
},
onError: () => {
notification("Errors", "Failed to deleted ", "success")
notification("Error", "Failed to delete the allocation ", "error")
},
})
}
Expand Down Expand Up @@ -119,7 +123,11 @@ const EditAllocationDrawer = ({
},
{
onSuccess: () => {
notification("Success", "Allocation updated successfully", "success")
notification(
"Allocation was updated",
"The allocation change was saved.",
"success"
)
close()
},
onError: () => {
Expand Down Expand Up @@ -265,6 +273,7 @@ const EditAllocationDrawer = ({
className="my-1 w-full border text-rose-50"
size="small"
onClick={handleDelete}
type="button"
>
Delete allocation
</Button>
Expand Down