fix publish date not resetting when changed radio field value
This commit is contained in:
parent
fddd3c8f3b
commit
568e1b1792
1 changed files with 24 additions and 16 deletions
|
@ -69,13 +69,17 @@ interface Message {
|
||||||
availableSecondLabel?: string;
|
availableSecondLabel?: string;
|
||||||
setAvailabilityDateLabel?: string;
|
setAvailabilityDateLabel?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DateFields {
|
||||||
|
publicationDate: string;
|
||||||
|
availableForPurchase?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface VisibilityCardProps {
|
export interface VisibilityCardProps {
|
||||||
children?: React.ReactNode | React.ReactNodeArray;
|
children?: React.ReactNode | React.ReactNodeArray;
|
||||||
data: {
|
data: DateFields & {
|
||||||
availableForPurchase?: string;
|
|
||||||
isAvailableForPurchase?: boolean;
|
isAvailableForPurchase?: boolean;
|
||||||
isPublished: boolean;
|
isPublished: boolean;
|
||||||
publicationDate: string;
|
|
||||||
visibleInListings?: boolean;
|
visibleInListings?: boolean;
|
||||||
};
|
};
|
||||||
errors: UserError[];
|
errors: UserError[];
|
||||||
|
@ -117,6 +121,21 @@ export const VisibilityCard: React.FC<VisibilityCardProps> = props => {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleRadioFieldChange = (type: keyof DateFields) => (
|
||||||
|
e: ChangeEvent
|
||||||
|
) => {
|
||||||
|
const { value } = e.target;
|
||||||
|
if (!value) {
|
||||||
|
onChange({
|
||||||
|
target: {
|
||||||
|
name: type,
|
||||||
|
value: null
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return onChange(e);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
<CardTitle
|
<CardTitle
|
||||||
|
@ -156,7 +175,7 @@ export const VisibilityCard: React.FC<VisibilityCardProps> = props => {
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
value={isPublished}
|
value={isPublished}
|
||||||
onChange={onChange}
|
onChange={handleRadioFieldChange("publicationDate")}
|
||||||
/>
|
/>
|
||||||
{!isPublished && (
|
{!isPublished && (
|
||||||
<DateVisibilitySelector
|
<DateVisibilitySelector
|
||||||
|
@ -226,18 +245,7 @@ export const VisibilityCard: React.FC<VisibilityCardProps> = props => {
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
value={isAvailable}
|
value={isAvailable}
|
||||||
onChange={e => {
|
onChange={handleRadioFieldChange("availableForPurchase")}
|
||||||
const { value } = e.target;
|
|
||||||
if (!value) {
|
|
||||||
onChange({
|
|
||||||
target: {
|
|
||||||
name: "availableForPurchase",
|
|
||||||
value: null
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return onChange(e);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
{!isAvailable && (
|
{!isAvailable && (
|
||||||
<DateVisibilitySelector
|
<DateVisibilitySelector
|
||||||
|
|
Loading…
Reference in a new issue