From 114243d36430d159a0a121cf7c9fadbc8c61fb48 Mon Sep 17 00:00:00 2001 From: Alessandro Mazzon Date: Fri, 10 Nov 2023 17:10:53 +0100 Subject: [PATCH] feat: added a private switch --- app/creator/create/BondscapeSwitch.tsx | 39 +++++++++++++++++++ app/creator/create/[[...id]]/MainSection.tsx | 8 ++++ app/creator/create/[[...id]]/useHooks.ts | 2 + app/creator/events/[id]/page.tsx | 15 +++++-- app/hooks/events/useCreateEvent.ts | 1 + .../axios/requests/CreateEvent/index.ts | 2 + .../axios/requests/EditEvent/index.ts | 2 + .../bondscape/fragments/EventsFields.ts | 1 + app/types/event.ts | 3 ++ 9 files changed, 70 insertions(+), 3 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..f3a67e6 --- /dev/null +++ b/app/creator/create/BondscapeSwitch.tsx @@ -0,0 +1,39 @@ +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 SmallTextInput = ({ 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 SmallTextInput; 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..88b4d48 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 ? (
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/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 {