Skip to content

Commit

Permalink
Merge branch 'develop' into fix/categories-product-details-page
Browse files Browse the repository at this point in the history
  • Loading branch information
olivermrbl authored Mar 31, 2023
2 parents 308f0fe + 4342ac8 commit 5618a4c
Show file tree
Hide file tree
Showing 59 changed files with 1,898 additions and 957 deletions.
7 changes: 7 additions & 0 deletions .changeset/famous-bananas-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@medusajs/admin-ui": patch
"@medusajs/medusa": patch
---

feat(admin-ui): Adds metadata forms to all applicable domains in the UI.
fix(medusa): Fixes an issue where metadata was not being set for order addresses using `setMetadata`.
1 change: 1 addition & 0 deletions packages/admin-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"@testing-library/user-event": "^14.4.3",
"@types/pluralize": "^0.0.29",
"@types/react": "^18.0.27",
"@types/react-datepicker": "^4.10.0",
"@types/react-dom": "^18.0.10",
"@types/react-table": "^7.7.9",
"typescript": "^4.9.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import InputHeader from "../../fundamentals/input-header"
import CustomHeader from "./custom-header"
import { DateTimePickerProps } from "./types"

const getDateClassname = (d, tempDate) => {
const getDateClassname = (d: Date, tempDate: Date) => {
return moment(d).format("YY,MM,DD") === moment(tempDate).format("YY,MM,DD")
? "date chosen"
: `date ${
Expand All @@ -29,12 +29,18 @@ const DatePicker: React.FC<DateTimePickerProps> = ({
tooltipContent,
tooltip,
}) => {
const [tempDate, setTempDate] = useState(date)
const [tempDate, setTempDate] = useState<Date | null>(date || null)
const [isOpen, setIsOpen] = useState(false)

useEffect(() => setTempDate(date), [isOpen])

const submitDate = () => {
if (!tempDate || !date) {
onSubmitDate(null)
setIsOpen(false)
return
}

// update only date, month and year
const newDate = new Date(date.getTime())
newDate.setUTCDate(tempDate.getUTCDate())
Expand Down Expand Up @@ -68,7 +74,9 @@ const DatePicker: React.FC<DateTimePickerProps> = ({
<ArrowDownIcon size={16} />
</div>
<label className="w-full text-left">
{moment(date).format("ddd, DD MMM YYYY")}
{date
? moment(date).format("ddd, DD MMM YYYY")
: "---, -- -- ----"}
</label>
</InputContainer>
</button>
Expand All @@ -78,7 +86,10 @@ const DatePicker: React.FC<DateTimePickerProps> = ({
sideOffset={8}
className="rounded-rounded border-grey-20 bg-grey-0 shadow-dropdown w-full border px-8"
>
<CalendarComponent date={tempDate} onChange={setTempDate} />
<CalendarComponent
date={tempDate}
onChange={(date) => setTempDate(date)}
/>
<div className="mb-8 mt-5 flex w-full">
<Button
variant="ghost"
Expand All @@ -101,7 +112,18 @@ const DatePicker: React.FC<DateTimePickerProps> = ({
)
}

export const CalendarComponent = ({ date, onChange }) => (
type CalendarComponentProps = {
date: Date | null
onChange: (
date: Date | null,
event: React.SyntheticEvent<any, Event> | undefined
) => void
}

export const CalendarComponent = ({
date,
onChange,
}: CalendarComponentProps) => (
<ReactDatePicker
selected={date}
inline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const TimePicker: React.FC<DateTimePickerProps> = ({
<ClockIcon size={16} />
<span className="mx-1">UTC</span>
<span className="text-grey-90">
{moment.utc(date).format("HH:mm")}
{date ? moment.utc(date).format("HH:mm") : "--:--"}
</span>
</div>
</InputContainer>
Expand All @@ -84,13 +84,13 @@ const TimePicker: React.FC<DateTimePickerProps> = ({
<NumberScroller
numbers={hourNumbers}
selected={selectedHour}
onSelect={(n) => setSelectedHour(n)}
onSelect={(n) => setSelectedHour(n as number)}
className="pr-4"
/>
<NumberScroller
numbers={minuteNumbers}
selected={selectedMinute}
onSelect={(n) => setSelectedMinute(n)}
onSelect={(n) => setSelectedMinute(n as number)}
/>
<div className="to-grey-0 h-xlarge absolute bottom-4 left-0 right-0 z-10 bg-gradient-to-b from-transparent" />
</PopoverPrimitive.Content>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InputHeaderProps } from "../../fundamentals/input-header"

export type DateTimePickerProps = {
date: Date
onSubmitDate: (newDate: Date) => void
date: Date | null
onSubmitDate: (newDate: Date | null) => void
} & InputHeaderProps
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import FormValidator from "../../../../utils/form-validator"
import { NestedForm } from "../../../../utils/nested-form"
import InputField from "../../../molecules/input"

export type CustomerGroupGeneralFormType = {
name: string
}

type CustomerGroupGeneralFormProps = {
form: NestedForm<CustomerGroupGeneralFormType>
}

export const CustomerGroupGeneralForm = ({
form,
}: CustomerGroupGeneralFormProps) => {
const {
register,
path,
formState: { errors },
} = form

return (
<div>
<InputField
label="Name"
required
{...register(path("name"), {
required: FormValidator.required("Name"),
})}
errors={errors}
/>
</div>
)
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import { Controller } from "react-hook-form"
import { NestedForm } from "../../../../utils/nested-form"
import DatePicker from "../../../atoms/date-picker/date-picker"
import TimePicker from "../../../atoms/date-picker/time-picker"
import AvailabilityDuration from "../../../molecules/availability-duration"
import InputField from "../../../molecules/input"
import SwitchableItem from "../../../molecules/switchable-item"

export type DiscountConfigurationFormType = {
starts_at: Date
ends_at: Date | null
usage_limit: number | null
valid_duration: string | null
}

type DiscountConfigurationFormProps = {
form: NestedForm<DiscountConfigurationFormType>
isDynamic?: boolean
}

const DiscountConfigurationForm = ({
form,
isDynamic,
}: DiscountConfigurationFormProps) => {
const { control, path } = form

return (
<div>
<div className="gap-y-large flex flex-col">
<Controller
name={path("starts_at")}
control={control}
render={({ field: { onChange, value } }) => {
return (
<SwitchableItem
open={!!value}
onSwitch={() => {
if (value) {
onChange(null)
} else {
onChange(new Date())
}
}}
title="Discount has a start date?"
description="Schedule the discount to activate in the future."
>
<div className="gap-x-xsmall flex items-center">
<DatePicker
date={value!}
label="Start date"
onSubmitDate={onChange}
/>
<TimePicker
label="Start time"
date={value!}
onSubmitDate={onChange}
/>
</div>
</SwitchableItem>
)
}}
/>
<Controller
name={path("ends_at")}
control={control}
render={({ field: { value, onChange } }) => {
return (
<SwitchableItem
open={!!value}
onSwitch={() => {
if (value) {
onChange(null)
} else {
onChange(
new Date(new Date().getTime() + 7 * 24 * 60 * 60 * 1000)
)
}
}}
title="Discount has an expiry date?"
description="Schedule the discount to deactivate in the future."
>
<div className="gap-x-xsmall flex items-center">
<DatePicker
date={value!}
label="Expiry date"
onSubmitDate={onChange}
/>
<TimePicker
label="Expiry time"
date={value!}
onSubmitDate={onChange}
/>
</div>
</SwitchableItem>
)
}}
/>
<Controller
name={path("usage_limit")}
control={control}
render={({ field: { value, onChange } }) => {
return (
<SwitchableItem
open={!!value}
onSwitch={() => {
if (value) {
onChange(null)
} else {
onChange(10)
}
}}
title="Limit the number of redemtions?"
description="Limit applies across all customers, not per customer."
>
<InputField
label="Number of redemptions"
type="number"
placeholder="5"
min={1}
defaultValue={value ?? undefined}
onChange={(value) => onChange(value.target.valueAsNumber)}
/>
</SwitchableItem>
)
}}
/>
{isDynamic && (
<Controller
name={path("valid_duration")}
control={control}
render={({ field: { onChange, value } }) => {
return (
<SwitchableItem
open={!!value}
onSwitch={() => {
if (value) {
onChange(null)
} else {
onChange("P0Y0M0DT00H00M")
}
}}
title="Availability duration?"
description="Set the duration of the discount."
>
<AvailabilityDuration
value={value ?? undefined}
onChange={onChange}
/>
</SwitchableItem>
)
}}
/>
)}
</div>
</div>
)
}

export default DiscountConfigurationForm
Loading

0 comments on commit 5618a4c

Please sign in to comment.