fix: availability creation and expand/collapse settings (#882)
* fix: availability creation and expand/collapse settings * additional fixes * Update pages/api/availability/eventtype.ts Co-authored-by: Alex Johansson <alexander@n1s.se> * update branch * fix: more fixes Co-authored-by: Alex Johansson <alexander@n1s.se> Co-authored-by: Bailey Pumfleet <pumfleet@hey.com> Co-authored-by: Mihai Colceriu <colceriumi@gmail.com>
This commit is contained in:
parent
683713e73f
commit
f27b0b3cad
6 changed files with 45 additions and 17 deletions
|
@ -73,6 +73,7 @@ export const localeLabels: localeType = {
|
||||||
pt: "Portuguese",
|
pt: "Portuguese",
|
||||||
ro: "Romanian",
|
ro: "Romanian",
|
||||||
nl: "Dutch",
|
nl: "Dutch",
|
||||||
|
"pt-BR": "Portuguese (Brazilian)",
|
||||||
};
|
};
|
||||||
|
|
||||||
export type OptionType = {
|
export type OptionType = {
|
||||||
|
|
|
@ -30,6 +30,10 @@ export type AdvancedOptions = {
|
||||||
label: string;
|
label: string;
|
||||||
avatar: string;
|
avatar: string;
|
||||||
}[];
|
}[];
|
||||||
|
availability?: { openingHours: OpeningHours[]; dateOverrides: DateOverride[] };
|
||||||
|
customInputs?: EventTypeCustomInput[];
|
||||||
|
timeZone: string;
|
||||||
|
hidden: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type EventTypeCustomInput = {
|
export type EventTypeCustomInput = {
|
||||||
|
|
|
@ -4,7 +4,7 @@ const path = require("path");
|
||||||
module.exports = {
|
module.exports = {
|
||||||
i18n: {
|
i18n: {
|
||||||
defaultLocale: "en",
|
defaultLocale: "en",
|
||||||
locales: ["en", "fr", "it", "ru", "es", "de", "pt", "ro", "nl"],
|
locales: ["en", "fr", "it", "ru", "es", "de", "pt", "ro", "nl", "pt-BR"],
|
||||||
},
|
},
|
||||||
localePath: path.resolve("./public/static/locales"),
|
localePath: path.resolve("./public/static/locales"),
|
||||||
};
|
};
|
||||||
|
|
|
@ -144,6 +144,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
const openingHours = req.body.availability.openingHours || [];
|
const openingHours = req.body.availability.openingHours || [];
|
||||||
// const overrides = req.body.availability.dateOverrides || [];
|
// const overrides = req.body.availability.dateOverrides || [];
|
||||||
|
|
||||||
|
const eventTypeId = +req.body.id;
|
||||||
|
if (eventTypeId) {
|
||||||
|
await prisma.availability.deleteMany({
|
||||||
|
where: {
|
||||||
|
eventTypeId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Promise.all(
|
Promise.all(
|
||||||
openingHours.map((schedule) =>
|
openingHours.map((schedule) =>
|
||||||
prisma.availability.create({
|
prisma.availability.create({
|
||||||
|
|
|
@ -136,7 +136,7 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||||
|
|
||||||
const titleRef = useRef<HTMLInputElement>(null);
|
const titleRef = useRef<HTMLInputElement>(null);
|
||||||
const eventNameRef = useRef<HTMLInputElement>(null);
|
const eventNameRef = useRef<HTMLInputElement>(null);
|
||||||
const isAdvancedSettingsVisible = !!eventNameRef.current;
|
const [advancedSettingsVisible, setAdvancedSettingsVisible] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSelectedTimeZone(eventType.timeZone || "");
|
setSelectedTimeZone(eventType.timeZone || "");
|
||||||
|
@ -150,7 +150,7 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||||
const enteredTitle: string = titleRef.current!.value;
|
const enteredTitle: string = titleRef.current!.value;
|
||||||
|
|
||||||
const advancedPayload: AdvancedOptions = {};
|
const advancedPayload: AdvancedOptions = {};
|
||||||
if (isAdvancedSettingsVisible) {
|
if (advancedSettingsVisible) {
|
||||||
advancedPayload.eventName = eventNameRef.current.value;
|
advancedPayload.eventName = eventNameRef.current.value;
|
||||||
advancedPayload.periodType = periodType?.type;
|
advancedPayload.periodType = periodType?.type;
|
||||||
advancedPayload.periodDays = asNumberOrUndefined(formData.periodDays);
|
advancedPayload.periodDays = asNumberOrUndefined(formData.periodDays);
|
||||||
|
@ -166,6 +166,12 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||||
formData.price ? Math.round(parseFloat(asStringOrThrow(formData.price)) * 100) :
|
formData.price ? Math.round(parseFloat(asStringOrThrow(formData.price)) * 100) :
|
||||||
/* otherwise */ 0;
|
/* otherwise */ 0;
|
||||||
advancedPayload.currency = currency;
|
advancedPayload.currency = currency;
|
||||||
|
advancedPayload.availability = enteredAvailability || undefined;
|
||||||
|
advancedPayload.customInputs = customInputs;
|
||||||
|
advancedPayload.timeZone = selectedTimeZone;
|
||||||
|
advancedPayload.hidden = hidden;
|
||||||
|
advancedPayload.disableGuests = formData.disableGuests === "on";
|
||||||
|
advancedPayload.requiresConfirmation = formData.requiresConfirmation === "on";
|
||||||
}
|
}
|
||||||
|
|
||||||
const payload: EventTypeInput = {
|
const payload: EventTypeInput = {
|
||||||
|
@ -174,13 +180,7 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||||
slug: asStringOrThrow(formData.slug),
|
slug: asStringOrThrow(formData.slug),
|
||||||
description: asStringOrThrow(formData.description),
|
description: asStringOrThrow(formData.description),
|
||||||
length: asNumberOrThrow(formData.length),
|
length: asNumberOrThrow(formData.length),
|
||||||
requiresConfirmation: formData.requiresConfirmation === "on",
|
|
||||||
disableGuests: formData.disableGuests === "on",
|
|
||||||
hidden,
|
|
||||||
locations,
|
locations,
|
||||||
customInputs,
|
|
||||||
timeZone: selectedTimeZone,
|
|
||||||
availability: enteredAvailability || undefined,
|
|
||||||
...advancedPayload,
|
...advancedPayload,
|
||||||
...(team
|
...(team
|
||||||
? {
|
? {
|
||||||
|
@ -620,14 +620,18 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||||
<Disclosure>
|
<Disclosure>
|
||||||
{({ open }) => (
|
{({ open }) => (
|
||||||
<>
|
<>
|
||||||
<Disclosure.Button className="flex w-full">
|
<div onClick={() => setAdvancedSettingsVisible(!advancedSettingsVisible)}>
|
||||||
<ChevronRightIcon
|
<Disclosure.Button className="flex w-full">
|
||||||
className={`${open ? "transform rotate-90" : ""} w-5 h-5 text-neutral-500 ml-auto`}
|
<ChevronRightIcon
|
||||||
/>
|
className={`${
|
||||||
<span className="text-sm font-medium text-neutral-700">
|
open ? "transform rotate-90" : ""
|
||||||
{t("show_advanced_settings")}
|
} w-5 h-5 text-neutral-500 ml-auto`}
|
||||||
</span>
|
/>
|
||||||
</Disclosure.Button>
|
<span className="text-sm font-medium text-neutral-700">
|
||||||
|
{t("show_advanced_settings")}
|
||||||
|
</span>
|
||||||
|
</Disclosure.Button>
|
||||||
|
</div>
|
||||||
<Disclosure.Panel className="space-y-6">
|
<Disclosure.Panel className="space-y-6">
|
||||||
<div className="items-center block sm:flex">
|
<div className="items-center block sm:flex">
|
||||||
<div className="mb-4 min-w-48 sm:mb-0">
|
<div className="mb-4 min-w-48 sm:mb-0">
|
||||||
|
@ -1135,6 +1139,15 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
team: {
|
||||||
|
members: {
|
||||||
|
some: {
|
||||||
|
userId: session.user.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
userId: session.user.id,
|
userId: session.user.id,
|
||||||
},
|
},
|
||||||
|
|
1
public/static/locales/pt-BR/common.json
Normal file
1
public/static/locales/pt-BR/common.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{}
|
Loading…
Reference in a new issue