Skip to content

Commit

Permalink
some bugs resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessandro Mazzon committed Nov 2, 2023
1 parent a44a7ac commit 3adfabc
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 27 deletions.
2 changes: 1 addition & 1 deletion app/creator/create/[[...id]]/CreateTicketCategory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const CreateTicketCategory = ({
/>
<BigTextInput
title={"Description"}
inputName={"ticketDescription"}
inputName={"description"}
placeholder={
"Add an optional description of the advantages granted by your NFT ticket, if any."
}
Expand Down
17 changes: 11 additions & 6 deletions app/creator/create/[[...id]]/MainSection.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { ErrorMessage, Form, FormikProps } from "formik";
import CoverPicDropZone from "@/creator/create/CoverPicDropZone";
import BondscapeButton from "@/components/BondscapeButton";
import BigTextInput from "@/creator/create/BigTextInput";
import BondscapeDateTimePicker from "@/creator/create/BondscapeDateTimePicker/BondscapeDateTimePicker";
import BondscapeSelectCategory from "@/creator/create/BondscapeSelectCategory";
import SmallTextInput from "@/creator/create/SmallTextInput";
import LocationInput from "@/creator/create/LocationInput";
import BondscapeSelectCoHosts from "@/creator/create/BondscapeSelectCoHosts";
import BondscapeSelectTags from "@/creator/create/BondscapeSelectTags";
import BondscapeButton from "@/components/BondscapeButton";
import React from "react";
import CoverPicDropZone from "@/creator/create/CoverPicDropZone";
import LocationInput from "@/creator/create/LocationInput";
import SmallTextInput from "@/creator/create/SmallTextInput";
import useUser from "@/hooks/user/useUser";
import { CreateEventValues, Organizer } from "@/types/event";
import { ErrorMessage, Form, FormikProps } from "formik";
import React from "react";

interface MainSectionProps {
readonly title: string;
Expand Down Expand Up @@ -90,6 +90,11 @@ const MainSection = ({
onChangeStart={(value) => setFieldValue("startDate", value)}
onChangeEnd={(value) => setFieldValue("endDate", value)}
/>
<div className="text-bondscape-text_neutral_900 text-[12px] font-normal">
{
"The start/end time of the event will be in the time zone based on where the event will be held."
}
</div>
<BondscapeSelectCategory
initialCategories={values.categories}
required={false}
Expand Down
50 changes: 31 additions & 19 deletions app/hooks/events/useCreateEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ export const useCreateEvent = () => {
(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) {
Expand All @@ -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,
Expand All @@ -143,27 +150,21 @@ export const useCreateEvent = () => {
tags: values.tags,
};

console.log(eventParams.startDate);

if (eventId) {
eventCreationResult = await EditEvent({
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,
});
}),
Expand All @@ -178,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<any, Error>[] = [];
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,
);
Expand All @@ -207,8 +221,6 @@ export const useCreateEvent = () => {
: "Event updated successfully",
);
router.replace(`/creator/events`);
} else {
toast.error(eventCreationResult.error.message);
}
},
[createTicketCategory, router, ticketCategoriesToDelete, user],
Expand Down
10 changes: 9 additions & 1 deletion app/services/axios/requests/EditEvent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ const EditEvent = ({
website,
}: EventRequestParams & {
eventId: string;
}): ResultAsync<any, Error> => {
}): ResultAsync<
{
data: {
event_id: string;
};
type: "create" | "edit";
},
Error
> => {
return ResultAsync.fromPromise(
axiosInstance.put(`/events/${eventId}`, {
status,
Expand Down

0 comments on commit 3adfabc

Please sign in to comment.