Skip to content

Commit

Permalink
Merge branch 'develop' into feat/normalize-db-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
olivermrbl authored Apr 4, 2024
2 parents bdde2b2 + fd3fc13 commit 0ac6593
Show file tree
Hide file tree
Showing 60 changed files with 779 additions and 300 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
},
"actions": {
"save": "Save",
"saveAsDraft": "Save as draft",
"create": "Create",
"delete": "Delete",
"remove": "Remove",
Expand Down Expand Up @@ -151,7 +152,7 @@
"attributes": "Attributes",
"editProduct": "Edit Product",
"editAttributes": "Edit Attributes",
"organization": "Organization",
"organization": "Organize",
"editOrganization": "Edit Organization",
"options": "Options",
"editOptions": "Edit Options",
Expand All @@ -171,10 +172,7 @@
"deleteImageLabel": "Delete current image",
"noMediaLabel": "The product has no associated media."
},
"titleHint": "Give your product a short and clear title.<0/>50-60 characters is the recommended length for search engines.",
"descriptionHint": "Give your product a short and clear description.<0/>120-160 characters is the recommended length for search engines.",
"discountableHint": "When unchecked discounts will not be applied to this product.",
"handleTooltip": "The handle is used to reference the product in your storefront. If not specified, the handle will be generated from the product title.",
"availableInSalesChannels": "Available in <0>{{x}}</0> of <1>{{y}}</1> sales channels",
"noSalesChannels": "Not available in any sales channels",
"variantCount_one": "{{count}} variant",
Expand All @@ -186,6 +184,61 @@
"proposed": "Proposed",
"rejected": "Rejected"
},
"fields": {
"title": {
"label": "Title",
"hint": "Give your product a short and clear title.<0/>50-60 characters is the recommended length for search engines."
},
"subtitle": {
"label": "Subtitle"
},
"handle": {
"label": "Handle",
"tooltip": "The handle is used to reference the product in your storefront. If not specified, the handle will be generated from the product title."
},
"description": {
"label": "Description",
"hint": "Give your product a short and clear description.<0/>120-160 characters is the recommended length for search engines."
},
"discountable": {
"label": "Discountable",
"hint": "When unchecked discounts will not be applied to this product"
},
"type": {
"label": "Type"
},
"collection": {
"label": "Collection"
},
"categories": {
"label": "Categories"
},
"tags": {
"label": "Tags"
},
"sales_channels": {
"label": "Sales channels",
"hint": "This product will only be available in the default sales channel if left untouched"
},
"countryOrigin": {
"label": "Country of origin"
},
"material": {
"label": "Material"
},
"width": {
"label": "Width"
},
"length": {
"label": "Length"
},
"height": {
"label": "Height"
},
"weight": {
"label": "Weight"
}
},
"variant": {
"edit": {
"header": "Edit Variant"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { ArrowDownTray } from "@medusajs/icons"
import { Text, clx } from "@medusajs/ui"
import { ChangeEvent, DragEvent, useRef, useState } from "react"

export interface FileType {
id: string
url: string
file: File
}

export interface FileUploadProps {
label: string
hint?: string
hasError?: boolean
formats: string[]
onUploaded: (files: FileType[]) => void
}

export const FileUpload = ({
label,
hint,
hasError,
formats,
onUploaded,
}: FileUploadProps) => {
const [isDragOver, setIsDragOver] = useState<boolean>(false)
const inputRef = useRef<HTMLInputElement>(null)
const dropZoneRef = useRef<HTMLButtonElement>(null)

const handleOpenFileSelector = () => {
inputRef.current?.click()
}

const handleDragEnter = (event: DragEvent) => {
event.preventDefault()
event.stopPropagation()

const files = event.dataTransfer?.files
if (!files) {
return
}

setIsDragOver(true)
}

const handleDragLeave = (event: DragEvent) => {
event.preventDefault()
event.stopPropagation()

if (
!dropZoneRef.current ||
dropZoneRef.current.contains(event.relatedTarget as Node)
) {
return
}

setIsDragOver(false)
}

const handleUploaded = (files: FileList | null) => {
if (!files) {
return
}

const fileList = Array.from(files)
const fileObj = fileList.map((file) => {
const previewUrl = URL.createObjectURL(file)
return {
id: crypto.randomUUID(),
url: previewUrl,
file,
}
})

onUploaded(fileObj)
}

const handleDrop = (event: DragEvent) => {
event.preventDefault()
event.stopPropagation()

setIsDragOver(false)

handleUploaded(event.dataTransfer?.files)
}

const handleFileChange = async (event: ChangeEvent<HTMLInputElement>) => {
handleUploaded(event.target.files)
}

return (
<div>
<button
ref={dropZoneRef}
type="button"
onClick={handleOpenFileSelector}
onDrop={handleDrop}
onDragOver={(e) => e.preventDefault()}
onDragEnter={handleDragEnter}
onDragLeave={handleDragLeave}
className={clx(
"bg-ui-bg-component border-ui-border-strong transition-fg group flex w-full flex-col items-center gap-y-2 rounded-lg border border-dashed p-8",
"hover:border-ui-border-interactive focus:border-ui-border-interactive",
"focus:shadow-borders-focus outline-none focus:border-solid",
{
"!border-ui-border-error": hasError,
"!border-ui-border-interactive": isDragOver,
}
)}
>
<div className="text-ui-fg-subtle group-disabled:text-ui-fg-disabled flex items-center gap-x-2">
<ArrowDownTray />
<Text>{label}</Text>
</div>
{!!hint && (
<Text
size="small"
leading="compact"
className="text-ui-fg-muted group-disabled:text-ui-fg-disabled"
>
{hint}
</Text>
)}
</button>
<input
hidden
ref={inputRef}
onChange={handleFileChange}
type="file"
accept={formats.join(",")}
multiple
/>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./file-upload"
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as Dialog from "@radix-ui/react-dialog"

import {
ArrowRightOnRectangle,
BellAlert,
Expand All @@ -10,9 +12,6 @@ import {
User as UserIcon,
} from "@medusajs/icons"
import { Avatar, DropdownMenu, IconButton, Kbd, Text, clx } from "@medusajs/ui"
import * as Dialog from "@radix-ui/react-dialog"
import { useAdminDeleteSession, useAdminGetSession } from "medusa-react"
import { PropsWithChildren } from "react"
import {
Link,
Outlet,
Expand All @@ -21,9 +20,10 @@ import {
useMatches,
useNavigate,
} from "react-router-dom"
import { useAdminDeleteSession, useAdminGetSession } from "medusa-react"

import { PropsWithChildren } from "react"
import { Skeleton } from "../../common/skeleton"

import { queryClient } from "../../../lib/medusa"
import { useSearch } from "../../../providers/search-provider"
import { useSidebar } from "../../../providers/sidebar-provider"
Expand Down Expand Up @@ -121,6 +121,7 @@ const Breadcrumbs = () => {
const UserBadge = () => {
const isV2Enabled = V2_ENABLED === "true"

console.warn(isV2Enabled)
// Medusa V2 disabled
const v1 = useAdminGetSession({
enabled: !isV2Enabled,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { PencilSquare, Trash } from "@medusajs/icons"
import { StockLocationExpandedDTO } from "@medusajs/types"
import { Button, Container, Heading, Table, clx, usePrompt } from "@medusajs/ui"
import { Link, useNavigate, useSearchParams } from "react-router-dom"
import {
NoRecords,
NoResults,
} from "../../../../../components/common/empty-table-content/empty-table-content"
import {
PaginationState,
RowSelectionState,
Expand All @@ -9,20 +12,17 @@ import {
getCoreRowModel,
useReactTable,
} from "@tanstack/react-table"
import { PencilSquare, Trash } from "@medusajs/icons"
import {
useAdminDeleteStockLocation,
useAdminStockLocations,
} from "medusa-react"
import { useMemo, useState } from "react"
import { useTranslation } from "react-i18next"
import { Link, useNavigate, useSearchParams } from "react-router-dom"

import { ActionMenu } from "../../../../../components/common/action-menu"
import {
NoRecords,
NoResults,
} from "../../../../../components/common/empty-table-content/empty-table-content"
import { LocalizedTablePagination } from "../../../../../components/localization/localized-table-pagination"
import { StockLocationExpandedDTO } from "@medusajs/types"
import { useTranslation } from "react-i18next"

const PAGE_SIZE = 50

Expand All @@ -49,7 +49,7 @@ export const LocationsListTable = () => {
useAdminStockLocations({
limit: PAGE_SIZE,
offset: pageIndex * PAGE_SIZE,
expand: "address",
fields: "*address",
})

const columns = useColumns()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { v1Routes } from "./v1"
import { v2Routes } from "./v2"

const V2_ENABLED = import.meta.env.VITE_MEDUSA_V2 || false
const V2_ENABLED = import.meta.env.VITE_MEDUSA_V2 === "true"

const router = createBrowserRouter(V2_ENABLED ? v2Routes : v1Routes)

Expand Down
42 changes: 0 additions & 42 deletions packages/admin-next/dashboard/src/providers/router-provider/v1.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {
AdminCollectionsRes,
AdminCustomerGroupsRes,
AdminCustomersRes,
AdminDiscountsRes,
Expand Down Expand Up @@ -264,47 +263,6 @@ export const v1Routes: RouteObject[] = [
},
],
},
{
path: "/collections",
handle: {
crumb: () => "Collections",
},
children: [
{
path: "",
lazy: () => import("../../routes/collections/collection-list"),
children: [
{
path: "create",
lazy: () =>
import("../../routes/collections/collection-create"),
},
],
},
{
path: ":id",
handle: {
crumb: (data: AdminCollectionsRes) => data.collection.title,
},
lazy: () =>
import("../../routes/collections/collection-detail"),
children: [
{
path: "edit",
lazy: () =>
import("../../routes/collections/collection-edit"),
},
{
path: "add-products",
lazy: () =>
import(
"../../routes/collections/collection-add-products"
),
},
],
},
],
},
{
path: "/inventory",
handle: {
Expand Down
Loading

0 comments on commit 0ac6593

Please sign in to comment.