From fd84691ebae57a7a0eb6927ff0274a32c921dd9d Mon Sep 17 00:00:00 2001 From: Alessandro Mazzon Date: Sun, 5 Nov 2023 18:56:13 +0100 Subject: [PATCH] fix: misc bugfixes (#22) ## Description - Fixed a bug with co-hosts - Fixed a bug with event category description - Refactored how dates are sent into the server - Added a small advice regarding dates Closes: BON-812 BON-813 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] targeted the correct branch - [ ] provided a link to the relevant issue or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed all author checklist items have been addressed --- .../BondscapeDateTimePicker.tsx | 23 ++++----- .../create/[[...id]]/CreateTicketCategory.tsx | 7 ++- app/creator/create/[[...id]]/MainSection.tsx | 17 ++++--- app/hooks/events/useCreateEvent.ts | 48 ++++++++++++------- .../axios/requests/EditEvent/index.ts | 10 +++- 5 files changed, 67 insertions(+), 38 deletions(-) diff --git a/app/creator/create/BondscapeDateTimePicker/BondscapeDateTimePicker.tsx b/app/creator/create/BondscapeDateTimePicker/BondscapeDateTimePicker.tsx index ae01d9b..26b860a 100644 --- a/app/creator/create/BondscapeDateTimePicker/BondscapeDateTimePicker.tsx +++ b/app/creator/create/BondscapeDateTimePicker/BondscapeDateTimePicker.tsx @@ -1,5 +1,7 @@ import { DatePicker } from "antd"; import dayjs from "dayjs"; +import timezone from "dayjs/plugin/timezone"; +import utc from "dayjs/plugin/utc"; import React, { useState } from "react"; import "./style.css"; @@ -25,6 +27,9 @@ const BondscapeDateTimePicker = ({ const [minDate, setMinDate] = useState(); const [maxDate, setMaxDate] = useState(); + dayjs.extend(utc); + dayjs.extend(timezone); + const ClearIcon = () => { return ( current > maxDate || current < dayjs() - : (current) => current < dayjs() - } + disabledDate={maxDate ? (current) => current > maxDate : undefined} onChange={(date) => { - setMinDate(date || dayjs()); + setMinDate(date || undefined); if (date) { - onChangeStart(date.toISOString()); + onChangeStart(dayjs.utc(date).tz().format()); } else { onChangeStart(undefined); } @@ -96,15 +97,11 @@ const BondscapeDateTimePicker = ({
current < minDate - : (current) => current < dayjs().add(1, "hour") - } + disabledDate={minDate ? (current) => current < minDate : undefined} onChange={(date) => { setMaxDate(date || undefined); if (date) { - onChangeEnd(date.toISOString()); + onChangeEnd(dayjs.utc(date).tz().format()); } else { onChangeEnd(undefined); } diff --git a/app/creator/create/[[...id]]/CreateTicketCategory.tsx b/app/creator/create/[[...id]]/CreateTicketCategory.tsx index d4e706b..e8d76ac 100644 --- a/app/creator/create/[[...id]]/CreateTicketCategory.tsx +++ b/app/creator/create/[[...id]]/CreateTicketCategory.tsx @@ -112,7 +112,7 @@ const CreateTicketCategory = ({ /> +
+ { + "The availability time will be in the time zone based on where the event will be held." + } +
setFieldValue("startDate", value)} onChangeEnd={(value) => setFieldValue("endDate", value)} /> +
+ { + "The start/end time of the event will be in the time zone based on where the event will be held." + } +
{ (organizer) => organizer.organizerAddress, ); // Add the user's address to the list of organizers if it's a new event - if (!eventId) { - organizersAddresses.unshift(user.profile.address); - } + organizersAddresses.unshift(user.profile.address); + console.log(organizersAddresses); // Load the cover picture if it exists let coverPicUrl = values.coverPicUrl; if (values.coverPic) { @@ -127,7 +126,15 @@ export const useCreateEvent = () => { } } - let eventCreationResult: any; + let eventCreationResult: Result< + { + data: { + event_id: string; + }; + type: "create" | "edit"; + }, + Error + >; const eventParams = { status: values.status, @@ -148,20 +155,16 @@ export const useCreateEvent = () => { eventId, ...eventParams, }); - } else { - eventCreationResult = await CreateEvent({ - ...eventParams, - }); - } - - // Check the result: if it's ok, create ticket categories and then redirect to the events page and show a success toast, otherwise show an error toast - let ticketCategoryDeleteResult; - if (eventCreationResult.isOk() || eventId) { + if (eventCreationResult.isErr()) { + toast.error(eventCreationResult.error.message); + return; + } + let ticketCategoryDeleteResult; if (ticketCategoriesToDelete.length > 0) { ticketCategoryDeleteResult = await Promise.all( ticketCategoriesToDelete.map(async (ticketCategoryId) => { return DeleteTicketCategory({ - eventId: eventCreationResult.value.data.event_id ?? eventId, + eventId, categoryId: ticketCategoryId, }); }), @@ -176,13 +179,26 @@ export const useCreateEvent = () => { }); return; } + } else { + eventCreationResult = await CreateEvent({ + ...eventParams, + }); + + if (eventCreationResult.isErr()) { + toast.error(eventCreationResult.error.message); + return; + } + } + // Check the result: if it's ok, create ticket categories and then redirect to the events page and show a success toast, otherwise show an error toast + if (eventCreationResult.isOk()) { let ticketCategoryCreationResult: Result[] = []; + const id = eventCreationResult.value.data.event_id ?? eventId; if (values.ticketsCategories) { ticketCategoryCreationResult = await Promise.all( values.ticketsCategories.map((ticketCategory) => { return createTicketCategory( - eventCreationResult.value.data.event_id ?? eventId, + id, ticketCategory, ticketCategory.id, ); @@ -205,8 +221,6 @@ export const useCreateEvent = () => { : "Event updated successfully", ); router.replace(`/creator/events`); - } else { - toast.error(eventCreationResult.error.message); } }, [createTicketCategory, router, ticketCategoriesToDelete, user], diff --git a/app/services/axios/requests/EditEvent/index.ts b/app/services/axios/requests/EditEvent/index.ts index 982c750..96a9d5c 100644 --- a/app/services/axios/requests/EditEvent/index.ts +++ b/app/services/axios/requests/EditEvent/index.ts @@ -17,7 +17,15 @@ const EditEvent = ({ website, }: EventRequestParams & { eventId: string; -}): ResultAsync => { +}): ResultAsync< + { + data: { + event_id: string; + }; + type: "create" | "edit"; + }, + Error +> => { return ResultAsync.fromPromise( axiosInstance.put(`/events/${eventId}`, { status,