From f4cece1bcedeaaf54e8b683e04a27b41143a8eb0 Mon Sep 17 00:00:00 2001 From: Alessandro Mazzon Date: Sat, 11 Nov 2023 22:20:22 +0100 Subject: [PATCH] feat: private events (#24) ## Description - Now is possible to set up an event as private (default public) - The status of an event will be visible inside the event details --- ### 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... - [x] 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 --- app/creator/create/BondscapeSwitch.tsx | 40 +++++++++++++++++++ app/creator/create/[[...id]]/MainSection.tsx | 8 ++++ app/creator/create/[[...id]]/useHooks.ts | 2 + app/creator/events/[id]/page.tsx | 31 +++++++++----- app/hooks/events/useCreateEvent.ts | 1 + app/lib/DateUtils/index.ts | 3 ++ .../axios/requests/CreateEvent/index.ts | 2 + .../axios/requests/EditEvent/index.ts | 2 + .../bondscape/fragments/EventsFields.ts | 1 + app/types/event.ts | 3 ++ 10 files changed, 83 insertions(+), 10 deletions(-) create mode 100644 app/creator/create/BondscapeSwitch.tsx diff --git a/app/creator/create/BondscapeSwitch.tsx b/app/creator/create/BondscapeSwitch.tsx new file mode 100644 index 0000000..2db7813 --- /dev/null +++ b/app/creator/create/BondscapeSwitch.tsx @@ -0,0 +1,40 @@ +import { InputSwitch } from "primereact/inputswitch"; +import React, { useState } from "react"; + +interface Props { + readonly title: string; + readonly value?: boolean; + readonly onChange?: (value: boolean) => void; + readonly required?: boolean; +} + +const BondscapeSwitch = ({ title, value, onChange, required }: Props) => { + const [isChecked, setIsChecked] = useState(value || false); + return ( +
+
+ + {required && *} +
+ ({ + className: props.checked + ? "bg-bondscape-primary" + : "bg-bondscape-text_neutral_300", + }), + }} + checked={isChecked} + onChange={(e) => { + setIsChecked(e.value); + onChange && onChange(e.value); + }} + /> +
+ ); +}; + +export default BondscapeSwitch; diff --git a/app/creator/create/[[...id]]/MainSection.tsx b/app/creator/create/[[...id]]/MainSection.tsx index 621c396..41c4609 100644 --- a/app/creator/create/[[...id]]/MainSection.tsx +++ b/app/creator/create/[[...id]]/MainSection.tsx @@ -4,6 +4,7 @@ import BondscapeDateTimePicker from "@/creator/create/BondscapeDateTimePicker/Bo import BondscapeSelectCategory from "@/creator/create/BondscapeSelectCategory"; import BondscapeSelectCoHosts from "@/creator/create/BondscapeSelectCoHosts"; import BondscapeSelectTags from "@/creator/create/BondscapeSelectTags"; +import BondscapeSwitch from "@/creator/create/BondscapeSwitch"; import CoverPicDropZone from "@/creator/create/CoverPicDropZone"; import LocationInput from "@/creator/create/LocationInput"; import SmallTextInput from "@/creator/create/SmallTextInput"; @@ -131,6 +132,13 @@ const MainSection = ({ required={false} onChange={(tags) => setFieldValue("tags", tags)} /> + { + setFieldValue("isPrivate", newValue); + }} + /> diff --git a/app/creator/create/[[...id]]/useHooks.ts b/app/creator/create/[[...id]]/useHooks.ts index 7a2f231..ddadfc5 100644 --- a/app/creator/create/[[...id]]/useHooks.ts +++ b/app/creator/create/[[...id]]/useHooks.ts @@ -23,6 +23,7 @@ const useHooks = (eventId?: string) => { placeId: undefined, location: undefined, ticketsCategories: [], + isPrivate: false, }); // Memoized values @@ -72,6 +73,7 @@ const useHooks = (eventId?: string) => { organizers: event.organizers, tags: event.tags, website: event.website, + isPrivate: event.isPrivate, ticketsCategories: event.ticketsCategories.map((ticketCategory) => { return { id: ticketCategory.id, diff --git a/app/creator/events/[id]/page.tsx b/app/creator/events/[id]/page.tsx index 41575cd..3bfc86b 100644 --- a/app/creator/events/[id]/page.tsx +++ b/app/creator/events/[id]/page.tsx @@ -167,9 +167,18 @@ export default function EventDetails({ params }: { params: any }) { )} -
- {selectedEvent?.name ?? } -
+ {selectedEvent ? ( +
+
+ {selectedEvent?.name} +
+
+ {selectedEvent?.isPrivate ? "Private Event" : "Public Event"} +
+
+ ) : ( + + )} {selectedEvent ? (
@@ -238,13 +247,15 @@ export default function EventDetails({ params }: { params: any }) { ).time }
-
- {serializeTimezoneOffset( - extractTimezoneOffset( - selectedEvent?.startDateLocalized, - ), - )} -
+ {selectedEvent.startDateLocalized && ( +
+ {serializeTimezoneOffset( + extractTimezoneOffset( + selectedEvent.startDateLocalized, + ), + )} +
+ )}
) : ( diff --git a/app/hooks/events/useCreateEvent.ts b/app/hooks/events/useCreateEvent.ts index 8d5000d..6f86505 100644 --- a/app/hooks/events/useCreateEvent.ts +++ b/app/hooks/events/useCreateEvent.ts @@ -147,6 +147,7 @@ export const useCreateEvent = () => { website: values.website, placeId: values.placeId, tags: values.tags, + isPrivate: values.isPrivate, }; if (eventId) { diff --git a/app/lib/DateUtils/index.ts b/app/lib/DateUtils/index.ts index c27fe91..9708d6f 100644 --- a/app/lib/DateUtils/index.ts +++ b/app/lib/DateUtils/index.ts @@ -36,6 +36,9 @@ export const normalizeDateTime = (date: string): string => { * Utility function to extract the timezone offset from a RFC3339 encoded date time. */ export const extractTimezoneOffset = (date: string): TimezoneOffset => { + if (!date) { + return { hours: 0, minutes: 0 }; + } if (date.indexOf("Z") !== -1) { return { hours: 0, minutes: 0 }; } diff --git a/app/services/axios/requests/CreateEvent/index.ts b/app/services/axios/requests/CreateEvent/index.ts index 9b0a257..d8cce94 100644 --- a/app/services/axios/requests/CreateEvent/index.ts +++ b/app/services/axios/requests/CreateEvent/index.ts @@ -14,6 +14,7 @@ const CreateEvent = ({ placeId, tags, website, + isPrivate, }: EventRequestParams): ResultAsync => { return ResultAsync.fromPromise( axiosInstance.post("/events", { @@ -28,6 +29,7 @@ const CreateEvent = ({ organizers_addresses: organizersAddresses, categories_ids: categoriesIds, tags: tags, + is_private: isPrivate, }), (e: any) => e ?? Error("Error creating event"), ).map((response) => { diff --git a/app/services/axios/requests/EditEvent/index.ts b/app/services/axios/requests/EditEvent/index.ts index 96a9d5c..d95bad7 100644 --- a/app/services/axios/requests/EditEvent/index.ts +++ b/app/services/axios/requests/EditEvent/index.ts @@ -15,6 +15,7 @@ const EditEvent = ({ placeId, tags, website, + isPrivate, }: EventRequestParams & { eventId: string; }): ResultAsync< @@ -39,6 +40,7 @@ const EditEvent = ({ organizers_addresses: organizersAddresses, categories_ids: categoriesIds, tags: tags, + is_private: isPrivate, }), (e: any) => e ?? Error("Error editing event"), ).map((response) => { diff --git a/app/services/graphql/queries/bondscape/fragments/EventsFields.ts b/app/services/graphql/queries/bondscape/fragments/EventsFields.ts index 98a9634..4a562a1 100644 --- a/app/services/graphql/queries/bondscape/fragments/EventsFields.ts +++ b/app/services/graphql/queries/bondscape/fragments/EventsFields.ts @@ -41,6 +41,7 @@ const EventsFields = gql` detailsLink: details_link website tags + isPrivate: is_private ticketsCategories: tickets_categories { id name diff --git a/app/types/event.ts b/app/types/event.ts index 1ddf268..bb313ea 100644 --- a/app/types/event.ts +++ b/app/types/event.ts @@ -149,6 +149,7 @@ export interface Event { * Event tickets categories. */ ticketsCategories: EventTicketCategory[]; + isPrivate: boolean; } export interface TicketCategoryValues { @@ -218,6 +219,7 @@ export interface CreateEventValues { * Event tickets categories. */ ticketsCategories?: TicketCategoryValues[]; + isPrivate?: boolean; } export interface GQLEventsResult { @@ -255,6 +257,7 @@ export interface EventRequestParams { placeId?: string; organizersAddresses: string[]; tags?: string[]; + isPrivate?: boolean; } export interface TicketCategoryRequestParams {