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 isDynamic?: boolean } const DiscountConfigurationForm = ({ form, isDynamic, }: DiscountConfigurationFormProps) => { const { control, path } = form return (
{ return ( { if (value) { onChange(null) } else { onChange(new Date()) } }} title="Discount has a start date?" description="Schedule the discount to activate in the future." >
) }} /> { return ( { 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." >
) }} /> { return ( { if (value) { onChange(null) } else { onChange(10) } }} title="Limit the number of redemtions?" description="Limit applies across all customers, not per customer." > onChange(value.target.valueAsNumber)} /> ) }} /> {isDynamic && ( { return ( { if (value) { onChange(null) } else { onChange("P0Y0M0DT00H00M") } }} title="Availability duration?" description="Set the duration of the discount." > ) }} /> )}
) } export default DiscountConfigurationForm