Skip to content

Commit

Permalink
added modals to event creation page
Browse files Browse the repository at this point in the history
  • Loading branch information
BenKurrek committed Mar 22, 2024
1 parent 7580b17 commit 2b54a2d
Show file tree
Hide file tree
Showing 4 changed files with 238 additions and 30 deletions.
26 changes: 5 additions & 21 deletions src/features/create-drop/components/ticket/AcceptPaymentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const STRIPE_PURCHASE_IMAGE = purchaseWithStripe.href.replace(purchaseWithStripe
const contentItem = (title: string, subtitle: string) => {
return (
<VStack align="start" marginTop="1" spacing="0">
<Heading color="gray.800" fontFamily="body" fontSize="md" fontWeight="700" textAlign="left">
<Heading color="gray.700" fontFamily="body" fontSize="md" fontWeight="700" textAlign="left">
{title}
</Heading>
<Heading color="gray.500" fontFamily="body" fontSize="md" fontWeight="400" textAlign="left">
Expand Down Expand Up @@ -129,13 +129,7 @@ const AcceptPaymentForm = (props: EventStepFormProps) => {
return (
<HStack align="start" justify="space-between" marginTop="10">
<VStack align="start" alignItems="start">
<Heading
color="gray.800"
fontFamily="body"
fontSize="2xl"
fontWeight="700"
textAlign="left"
>
<Heading color="gray.800" fontSize="3xl" fontWeight="700" textAlign="left">
Enable Stripe Checkout
</Heading>
<Heading
Expand Down Expand Up @@ -219,13 +213,7 @@ const AcceptPaymentForm = (props: EventStepFormProps) => {
)}

<Divider bgColor="gray.300" height="3px" my="3" />
<Heading
color="gray.800"
fontFamily="body"
fontSize="2xl"
fontWeight="700"
textAlign="left"
>
<Heading color="gray.800" fontSize="3xl" fontWeight="700" marginTop="5" textAlign="left">
Enable $NEAR Checkout
</Heading>
<Heading
Expand All @@ -236,14 +224,10 @@ const AcceptPaymentForm = (props: EventStepFormProps) => {
fontWeight="400"
textAlign="left"
>
Allow attendees to purchase tickets with $NEAR. Attendees will need a NEAR wallet.
Allow attendees to purchase tickets with $NEAR. The funds will go directly into your
wallet.
</Heading>

{contentItem(
'Receive $NEAR',
'Any earnings will be deposited directly into your NEAR wallet.',
)}

<HStack justify="space-between" paddingTop="4" spacing="auto" width="100%">
<Heading
color="gray.800"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import {
Modal,
ModalOverlay,
ModalContent,
ModalHeader,
ModalBody,
ModalFooter,
Button,
Text,
VStack,
IconButton,
useToast,
} from '@chakra-ui/react';
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';

import { TicketIcon } from '@/components/Icons';
import { EVENTS_WORKER_BASE } from '@/constants/common';

interface EventCreationStatusModalProps {
isSuccess: boolean;
setIsOpen: () => void;
isOpen: boolean;
prevEventData?: {
priceByDropId?: Record<string, number>;
eventId: string;
stripeAccountId?: string;
};
}

export const EventCreationStatusModal = ({
isOpen,
setIsOpen,
isSuccess,
prevEventData,
}: EventCreationStatusModalProps) => {
const [isSetting, setIsSetting] = useState(false);
const navigate = useNavigate();
const toast = useToast();

const handlePostEventCreation = async () => {
if (isSuccess) {
setIsSetting(true);

if (prevEventData?.stripeAccountId !== undefined) {
let response: Response | undefined;
try {
const url = `${EVENTS_WORKER_BASE}/stripe/create-event`;
const body = {
priceByDropId: prevEventData.priceByDropId,
stripeAccountId: prevEventData.stripeAccountId,
eventId: prevEventData.eventId,
};
response = await fetch(url, {
method: 'POST',
body: JSON.stringify(body),
});
} catch (error) {
return;
}

if (!response?.ok) {
toast({
title: 'Unable to upload event to stripe',
description: `Please delete the event and try again later. If the error persists, contact support.`,
status: 'error',
duration: 10000,
isClosable: true,
});
} else {
localStorage.removeItem('EVENT_INFO_SUCCESS_DATA');
}
} else {
localStorage.removeItem('EVENT_INFO_SUCCESS_DATA');
}
setIsSetting(false);
navigate('/events');
} else {
localStorage.removeItem('EVENT_INFO_SUCCESS_DATA');
}
setIsOpen();
};

const bodyMessage = () => {
if (!isSuccess) {
return 'Please try again later. If the error persists, contact support.';
}

if (prevEventData?.stripeAccountId !== undefined) {
return 'The last step is to upload the event details to stripe so that you can receive funds.';
}

return `You're all set! Your event has been created and you can view it in the events page.`;
};

const buttonMessage = () => {
if (!isSuccess) {
return 'Close';
}

if (prevEventData?.stripeAccountId !== undefined) {
return 'Upload to Stripe';
}

return 'View Event';
};

return (
<Modal
isOpen={isOpen}
size="xl"
onClose={() => {
console.log('close');
}}
>
<ModalOverlay backdropFilter="blur(0px)" bg="blackAlpha.600" opacity="1" />
<ModalContent
maxH="90vh"
overflow="visible !important"
overflowY="auto"
paddingBottom="6"
paddingTop="12"
position="relative"
px="6"
>
<IconButton
aria-label="Ticket Icon"
bgColor="#DDF4FA" // Or any color that matches the modal background
border="2px solid transparent"
borderColor="blue.200"
borderRadius="full"
height="60px"
icon={<TicketIcon h="28px" w="28px" />} // replace with your actual icon
left="50%"
overflow="visible !important"
position="absolute"
top={-6} // Half of the icon size to make it center on the edge
transform="translateX(-50%) translateY(-10%)"
variant="outline"
width="60px"
zIndex={1500} // Higher than ModalContent to overlap
/>
<ModalHeader fontSize="lg" fontWeight="semibold">
{isSuccess ? 'Event Created Successfully' : 'Event Creation Failed'}
</ModalHeader>
<VStack align="start" spacing={4} textAlign="left">
<ModalBody pb={6}>
<Text color="gray.600" fontSize="md">
{bodyMessage()}
</Text>
</ModalBody>
<ModalFooter width="100%">
<Button
colorScheme="blue"
isLoading={isSetting}
width="100%"
onClick={handlePostEventCreation}
>
{buttonMessage()}
</Button>
</ModalFooter>
</VStack>
</ModalContent>
</Modal>
);
};
64 changes: 61 additions & 3 deletions src/features/create-drop/routes/CreateTicketDropPage.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { Button, HStack } from '@chakra-ui/react';
import { Button, HStack, useToast } from '@chakra-ui/react';
import { type ReactElement, useState, useEffect } from 'react';
import { type Action, type Wallet } from '@near-wallet-selector/core';

import keypomInstance from '@/lib/keypom';
import { get } from '@/utils/localStorage';
import { type IBreadcrumbItem } from '@/components/Breadcrumbs';
import { IconBox } from '@/components/IconBox';
import { LinkIcon } from '@/components/Icons';
import { Step } from '@/components/Step';
import { useAuthWalletContext } from '@/contexts/AuthWalletContext';
import { EVENTS_WORKER_BASE, KEYPOM_EVENTS_CONTRACT } from '@/constants/common';
import {
EVENTS_WORKER_BASE,
KEYPOM_EVENTS_CONTRACT,
KEYPOM_MARKETPLACE_CONTRACT,
} from '@/constants/common';

import { CreateTicketDropLayout } from '../components/CreateTicketDropLayout';
import { CollectInfoForm } from '../components/ticket/CollectInfoForm';
Expand All @@ -29,6 +34,7 @@ import {
serializeMediaForWorker,
} from '../components/ticket/helpers';
import { AcceptPaymentForm } from '../components/ticket/AcceptPaymentForm';
import { EventCreationStatusModal } from '../components/ticket/EventCreationStatusModal';

interface TicketStep {
title: string;
Expand Down Expand Up @@ -240,10 +246,18 @@ const placeholderData: TicketDropFormData = {
export default function NewTicketDrop() {
const [currentStep, setCurrentStep] = useState(0);
const [isModalOpen, setIsModalOpen] = useState(false);

const [eventCreationSuccess, setEventCreationSuccess] = useState<boolean | undefined>();
const [prevEventData, setPrevEventData] = useState<
| { priceByDropId?: Record<string, number>; eventId: string; stripeAccountId?: string }
| undefined
>();

const [isSettingKey, setIsSettingKey] = useState(false);
const [formData, setFormData] = useState<TicketDropFormData>(placeholderData);
const { selector, accountId } = useAuthWalletContext();
const [wallet, setWallet] = useState<Wallet>();
const toast = useToast();

useEffect(() => {
async function fetchWallet() {
Expand All @@ -260,6 +274,32 @@ export default function NewTicketDrop() {
fetchWallet();
}, [selector]);

useEffect(() => {
async function checkForEventCreation() {
const eventData = localStorage.getItem('EVENT_INFO_SUCCESS_DATA');

if (eventData) {
const { eventId, stripeAccountId, priceByDropId } = JSON.parse(eventData);
setPrevEventData({ priceByDropId, eventId, stripeAccountId });

try {
await keypomInstance.viewCall({
contractId: KEYPOM_MARKETPLACE_CONTRACT,
methodName: 'get_event_information',
args: { event_id: eventId },
});
setEventCreationSuccess(true);
} catch (e) {
setEventCreationSuccess(false);
}

localStorage.removeItem('EVENT_INFO_SUCCESS_DATA');
}
}

checkForEventCreation();
}, []);

const handleClearForm = () => {
switch (currentStep) {
case 0:
Expand Down Expand Up @@ -346,14 +386,24 @@ export default function NewTicketDrop() {
eventId,
priceByDropId,
};
localStorage.setItem('STRIPE_ACCOUNT_INFO', JSON.stringify(stripeAccountInfo));
localStorage.setItem('EVENT_INFO_SUCCESS_DATA', JSON.stringify(stripeAccountInfo));
} else {
localStorage.setItem('EVENT_INFO_SUCCESS_DATA', JSON.stringify({ eventId }));
}

await wallet.signAndSendTransaction({
signerId: accountId!,
receiverId: KEYPOM_EVENTS_CONTRACT,
actions,
});
} else {
toast({
title: 'Unable to upload event images',
description: `Please try again later. If the error persists, contact support.`,
status: 'error',
duration: 5000,
isClosable: true,
});
}
setIsSettingKey(false);
};
Expand Down Expand Up @@ -408,6 +458,14 @@ export default function NewTicketDrop() {
isSetting={isSettingKey}
onModalClose={handleModalClose}
/>
<EventCreationStatusModal
isOpen={eventCreationSuccess !== undefined}
isSuccess={eventCreationSuccess === true}
prevEventData={prevEventData}
setIsOpen={() => {
setEventCreationSuccess(undefined);
}}
/>
<CreateTicketDropLayout
breadcrumbs={breadcrumbs}
description={formSteps[currentStep].description}
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3378,9 +3378,9 @@ camelcase@^6.2.0:
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==

caniuse-lite@^1.0.30001587:
version "1.0.30001599"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001599.tgz#571cf4f3f1506df9bf41fcbb6d10d5d017817bce"
integrity sha512-LRAQHZ4yT1+f9LemSMeqdMpMxZcc4RMWdj4tiFe3G8tNkWK+E58g+/tzotb5cU6TbcVJLr4fySiAW7XmxQvZQA==
version "1.0.30001600"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001600.tgz#93a3ee17a35aa6a9f0c6ef1b2ab49507d1ab9079"
integrity sha512-+2S9/2JFhYmYaDpZvo0lKkfvuKIglrx68MwOBqMGHhQsNkLjB5xtc/TGoEPs+MxjSyN/72qer2g97nzR641mOQ==

capability@^0.2.5:
version "0.2.5"
Expand Down Expand Up @@ -4000,9 +4000,9 @@ electron-fetch@^1.7.2:
encoding "^0.1.13"

electron-to-chromium@^1.4.668:
version "1.4.714"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.714.tgz#708fdc8d5bdec824e41fe8b1b0e10af508a10946"
integrity sha512-OfnVHt+nMRH9Ua5koH/2gKlCAXbG+u1yXwLKyBVqNboBV34ZTwb846RUe8K5mtE1uhz0BXoMarZ13JCQr+sBtQ==
version "1.4.715"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.715.tgz#bb16bcf2a3537962fccfa746b5c98c5f7404ff46"
integrity sha512-XzWNH4ZSa9BwVUQSDorPWAUQ5WGuYz7zJUNpNif40zFCiCl20t8zgylmreNmn26h5kiyw2lg7RfTmeMBsDklqg==

elliptic@^6.5.3, elliptic@^6.5.5:
version "6.5.5"
Expand Down

0 comments on commit 2b54a2d

Please sign in to comment.