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",
|
||||
ro: "Romanian",
|
||||
nl: "Dutch",
|
||||
"pt-BR": "Portuguese (Brazilian)",
|
||||
};
|
||||
|
||||
export type OptionType = {
|
||||
|
|
|
@ -30,6 +30,10 @@ export type AdvancedOptions = {
|
|||
label: string;
|
||||
avatar: string;
|
||||
}[];
|
||||
availability?: { openingHours: OpeningHours[]; dateOverrides: DateOverride[] };
|
||||
customInputs?: EventTypeCustomInput[];
|
||||
timeZone: string;
|
||||
hidden: boolean;
|
||||
};
|
||||
|
||||
export type EventTypeCustomInput = {
|
||||
|
|
|
@ -4,7 +4,7 @@ const path = require("path");
|
|||
module.exports = {
|
||||
i18n: {
|
||||
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"),
|
||||
};
|
||||
|
|
|
@ -144,6 +144,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||
const openingHours = req.body.availability.openingHours || [];
|
||||
// const overrides = req.body.availability.dateOverrides || [];
|
||||
|
||||
const eventTypeId = +req.body.id;
|
||||
if (eventTypeId) {
|
||||
await prisma.availability.deleteMany({
|
||||
where: {
|
||||
eventTypeId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Promise.all(
|
||||
openingHours.map((schedule) =>
|
||||
prisma.availability.create({
|
||||
|
|
|
@ -136,7 +136,7 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
|||
|
||||
const titleRef = useRef<HTMLInputElement>(null);
|
||||
const eventNameRef = useRef<HTMLInputElement>(null);
|
||||
const isAdvancedSettingsVisible = !!eventNameRef.current;
|
||||
const [advancedSettingsVisible, setAdvancedSettingsVisible] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setSelectedTimeZone(eventType.timeZone || "");
|
||||
|
@ -150,7 +150,7 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
|||
const enteredTitle: string = titleRef.current!.value;
|
||||
|
||||
const advancedPayload: AdvancedOptions = {};
|
||||
if (isAdvancedSettingsVisible) {
|
||||
if (advancedSettingsVisible) {
|
||||
advancedPayload.eventName = eventNameRef.current.value;
|
||||
advancedPayload.periodType = periodType?.type;
|
||||
advancedPayload.periodDays = asNumberOrUndefined(formData.periodDays);
|
||||
|
@ -166,6 +166,12 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
|||
formData.price ? Math.round(parseFloat(asStringOrThrow(formData.price)) * 100) :
|
||||
/* otherwise */ 0;
|
||||
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 = {
|
||||
|
@ -174,13 +180,7 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
|||
slug: asStringOrThrow(formData.slug),
|
||||
description: asStringOrThrow(formData.description),
|
||||
length: asNumberOrThrow(formData.length),
|
||||
requiresConfirmation: formData.requiresConfirmation === "on",
|
||||
disableGuests: formData.disableGuests === "on",
|
||||
hidden,
|
||||
locations,
|
||||
customInputs,
|
||||
timeZone: selectedTimeZone,
|
||||
availability: enteredAvailability || undefined,
|
||||
...advancedPayload,
|
||||
...(team
|
||||
? {
|
||||
|
@ -620,14 +620,18 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
|||
<Disclosure>
|
||||
{({ open }) => (
|
||||
<>
|
||||
<div onClick={() => setAdvancedSettingsVisible(!advancedSettingsVisible)}>
|
||||
<Disclosure.Button className="flex w-full">
|
||||
<ChevronRightIcon
|
||||
className={`${open ? "transform rotate-90" : ""} w-5 h-5 text-neutral-500 ml-auto`}
|
||||
className={`${
|
||||
open ? "transform rotate-90" : ""
|
||||
} w-5 h-5 text-neutral-500 ml-auto`}
|
||||
/>
|
||||
<span className="text-sm font-medium text-neutral-700">
|
||||
{t("show_advanced_settings")}
|
||||
</span>
|
||||
</Disclosure.Button>
|
||||
</div>
|
||||
<Disclosure.Panel className="space-y-6">
|
||||
<div className="items-center block sm:flex">
|
||||
<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,
|
||||
},
|
||||
|
|
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