feat: ✨ Show dialog only for InPerson and Link locations (#2206)
This commit is contained in:
parent
b8980ced8e
commit
6ed945943a
1 changed files with 26 additions and 19 deletions
|
@ -274,6 +274,23 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const addLocation = (newLocationType: LocationType, details = {}) => {
|
||||||
|
const existingIdx = formMethods.getValues("locations").findIndex((loc) => newLocationType === loc.type);
|
||||||
|
if (existingIdx !== -1) {
|
||||||
|
const copy = formMethods.getValues("locations");
|
||||||
|
copy[existingIdx] = {
|
||||||
|
...formMethods.getValues("locations")[existingIdx],
|
||||||
|
...details,
|
||||||
|
};
|
||||||
|
formMethods.setValue("locations", copy);
|
||||||
|
} else {
|
||||||
|
formMethods.setValue(
|
||||||
|
"locations",
|
||||||
|
formMethods.getValues("locations").concat({ type: newLocationType, ...details })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const LocationOptions = () => {
|
const LocationOptions = () => {
|
||||||
if (!selectedLocation) {
|
if (!selectedLocation) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -457,8 +474,13 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||||
className="react-select-container focus:border-primary-500 focus:ring-primary-500 block w-full min-w-0 flex-1 rounded-sm border border-gray-300 sm:text-sm"
|
className="react-select-container focus:border-primary-500 focus:ring-primary-500 block w-full min-w-0 flex-1 rounded-sm border border-gray-300 sm:text-sm"
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
if (e?.value) {
|
if (e?.value) {
|
||||||
locationFormMethods.setValue("locationType", e.value);
|
const newLocationType: LocationType = e.value;
|
||||||
openLocationModal(e.value);
|
locationFormMethods.setValue("locationType", newLocationType);
|
||||||
|
if (newLocationType === LocationType.InPerson || newLocationType === LocationType.Link) {
|
||||||
|
openLocationModal(newLocationType);
|
||||||
|
} else {
|
||||||
|
addLocation(newLocationType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -1587,26 +1609,11 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||||
if (newLocation === LocationType.InPerson) {
|
if (newLocation === LocationType.InPerson) {
|
||||||
details = { address: values.locationAddress };
|
details = { address: values.locationAddress };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newLocation === LocationType.Link) {
|
if (newLocation === LocationType.Link) {
|
||||||
details = { link: values.locationLink };
|
details = { link: values.locationLink };
|
||||||
}
|
}
|
||||||
const existingIdx = formMethods
|
|
||||||
.getValues("locations")
|
addLocation(newLocation, details);
|
||||||
.findIndex((loc) => values.locationType === loc.type);
|
|
||||||
if (existingIdx !== -1) {
|
|
||||||
const copy = formMethods.getValues("locations");
|
|
||||||
copy[existingIdx] = {
|
|
||||||
...formMethods.getValues("locations")[existingIdx],
|
|
||||||
...details,
|
|
||||||
};
|
|
||||||
formMethods.setValue("locations", copy);
|
|
||||||
} else {
|
|
||||||
formMethods.setValue(
|
|
||||||
"locations",
|
|
||||||
formMethods.getValues("locations").concat({ type: values.locationType, ...details })
|
|
||||||
);
|
|
||||||
}
|
|
||||||
setShowLocationModal(false);
|
setShowLocationModal(false);
|
||||||
}}>
|
}}>
|
||||||
<Controller
|
<Controller
|
||||||
|
|
Loading…
Reference in a new issue