diff --git a/app/components/conferences/admin/EditEvent.js b/app/components/conferences/admin/EditEvent.js index ffb2d1fc..7ac20efb 100644 --- a/app/components/conferences/admin/EditEvent.js +++ b/app/components/conferences/admin/EditEvent.js @@ -15,7 +15,7 @@ import styles from "../../../styles/event.module.css"; import toast, { Toaster } from 'react-hot-toast'; -export const EditEvent = ({ event, handleToast }) => { +export const EditEvent = ({ event }) => { const [formState, setFormState] = useState({ name: event.data.attributes.name, description: event.data.attributes.description, @@ -110,8 +110,7 @@ export const EditEvent = ({ event, handleToast }) => { const tres = handleTicketUpdate(event.data.relationships.tickets.data[0].id, token) sessionStorage.setItem("event", JSON.stringify(res.data)) - - router.push("/conferences/admin/dashboard") + router.push(`/conferences/admin/c/${res.data.data.id}/sponsors`) } catch (e) { console.error("Event Update failed", e.response.data.error); if (e.response.status == 401) { diff --git a/app/components/conferences/admin/IndivEvent.js b/app/components/conferences/admin/IndivEvent.js index 8bd0e376..9844208d 100644 --- a/app/components/conferences/admin/IndivEvent.js +++ b/app/components/conferences/admin/IndivEvent.js @@ -16,6 +16,7 @@ import { Stack, Tab, Tabs, + Nav } from "react-bootstrap"; import { addEventSpeakers, @@ -23,10 +24,11 @@ import { getEventSpeakers, } from "../../../lib/conferences/eventCall"; import styles from "../../../styles/event.module.css"; -import { EditEvent , CustomToast} from "./EditEvent"; +import { EditEvent, CustomToast } from "./EditEvent"; import toast, { Toaster } from 'react-hot-toast'; +import { SponsorForm } from "./SponsorForm"; -export const IndivEventDash = ({ eid, event }) => { +export const IndivEventDash = ({ eid, event, active }) => { const [speakerInfo, setSpeakerInfo] = useState(null); const [modalShow, setModalShow] = useState(false); const [editSpeaker, setEditSpeaker] = useState({}); @@ -37,20 +39,26 @@ export const IndivEventDash = ({ eid, event }) => { authCookie = JSON.parse(authCookie); } + const pageRoute = { + "basic-detail": 0, + sponsors: 1, + sessions: 2, + }; + const fetchSpeaker = async () => { const res = await getEventSpeakers(eid, authCookie?.access_token); return res; }; // function to replace empty strings in the editSpeaker object - const replaceEmpty = (obj) => { + const replaceEmpty = (obj) => { for (const key in obj) { if (obj[key] === "") { obj[key] = null; } } return obj; - } + } const publishSpeaker = async () => { const sanitizedSpeaker = replaceEmpty(editSpeaker); @@ -91,13 +99,13 @@ export const IndivEventDash = ({ eid, event }) => { const res = await publishSpeaker(); setSpeakerInfo((oarr) => [...oarr, res.data.data]); toast.success('Speaker added successfully', { - duration : 20000 + duration: 20000 }) setModalShow(false); } } catch (e) { toast.error("An error occurred while publishing speaker", { - duration : 20000 + duration: 20000 }); } finally { setLoad(false); @@ -113,13 +121,13 @@ export const IndivEventDash = ({ eid, event }) => { const handleDelete = async (e) => { try { await deleteEventSpeaker(e.target.id, authCookie?.access_token); - toast.success('Speaker deleted successfully',{ - duration : 2000, + toast.success('Speaker deleted successfully', { + duration: 2000, }); setSpeakerInfo((oarr) => oarr.filter((spk) => spk.id !== e.target.id)); } catch (e) { - toast.error("An error occurred while deleting the Speaker",{ - duration : 2000, + toast.error("An error occurred while deleting the Speaker", { + duration: 2000, }); } }; @@ -127,25 +135,32 @@ export const IndivEventDash = ({ eid, event }) => { return ( <> - - -

Editing Event {event.data.attributes.name}

-
- - - - -
- -
-
- -
+ +

Editing Event {event.data.attributes.name}

+ + + + + + {pageRoute[active] == 0 && } + {pageRoute[active] == 1 && } + {pageRoute[active] == 2 && (
@@ -162,14 +177,12 @@ export const IndivEventDash = ({ eid, event }) => { fetchSpeaker={fetchSpeaker} handleDelete={handleDelete} /> -
- - - -
- - - {/* */} +
)} + {pageRoute[active] == undefined && + "Hey! You got yourself on an fabled isle."} + +
+ {/* */} ); }; @@ -188,7 +201,7 @@ const SpeakerList = ({ setSpeakerInfo(res.data); } catch (e) { toast.error("An error occurred while loading speakers", { - duration : 2000 + duration: 2000 }); } } @@ -199,35 +212,35 @@ const SpeakerList = ({ {Array.isArray(speakerInfo) && speakerInfo.length ? speakerInfo.map((spk) => { - return ( - - - - - - - - {spk.attributes.name} - - - - - - - - ); - }) + return ( + + + + + + + + {spk.attributes.name} + + + + + + + + ); + }) : "No Speaker found"} ); @@ -237,103 +250,103 @@ const SpeakerModal = (props) => { const { handleAddSpeaker, handleChange } = props; return ( <> - - - - - Add Speaker - - -
- - - Name - - - - Profile Pic URL - - - - Social links - - - - - - Short Biography - - - - Long Biography - - - - - - -
-
+ + + + + + + ); }; diff --git a/app/components/conferences/admin/SponsorForm.js b/app/components/conferences/admin/SponsorForm.js new file mode 100644 index 00000000..4ec39394 --- /dev/null +++ b/app/components/conferences/admin/SponsorForm.js @@ -0,0 +1,415 @@ +import { useEffect, useState } from "react"; +import { + Button, + Container, + Row, + Col, + Form, + InputGroup, + Toast, + Stack, + ListGroup, + ListGroupItem, + Modal, + ButtonGroup +} from "react-bootstrap"; +import Cookies from "js-cookie"; +import { useRouter } from "next/router"; +import { deleteSponsor, editEvent, getSponsorsDetails, publishSponsor, updateSponsor } from "../../../lib/conferences/eventCall"; +import styles from "../../../styles/event.module.css"; +import toast, { Toaster } from 'react-hot-toast'; + + +export const SponsorForm = ({ event }) => { + + const router = useRouter() + const [sponsors, setSponsors] = useState([]) + const [modalShow, setModalShow] = useState(false); + const [load, setLoad] = useState(false) + const [sponsorForm, setSponsorForm] = useState({}) + const isSponsorsEnabled = event.data.attributes["is-sponsors-enabled"]; + + const modalHandleChange = (e) => { + const tname = e.target.name; + const tvalue = e.target.value; + setSponsorForm({ ...sponsorForm, [tname]: tvalue }); + } + + const handleChange = (e,index) => { + const tname = e.target.name; + const tvalue = e.target.value; + + let changedSponsors = sponsors; + changedSponsors[index].attributes[tname] = tvalue; + + setSponsors(changedSponsors) + } + + const handleDelete = async (index) => { + try { + let token = Cookies.get("event_auth"); + token + ? (token = JSON.parse(token).access_token) + : new Error("Please, Sign in again"); + + await deleteSponsor(sponsors[index].id,token); + const newSponsorList = sponsors.filter((val,id) => {return id !== index}); + setSponsors(newSponsorList) + } catch (error) { + console.log("Error in deleting in the sponsor",error) + } + } + + const handleAddSponsor = async (e) => { + e.preventDefault() + try { + const data = { + data: { + relationships: { + event: { + data: { + type: "event", + id: event.data.id + } + } + }, + attributes: sponsorForm, + type: "sponsor" + } + } + + let token = Cookies.get("event_auth"); + token + ? (token = JSON.parse(token).access_token) + : new Error("Please, Sign in again"); + + if (!isSponsorsEnabled) { + + const eventData = { + data: { + attributes: { + name: event.data.attributes.name, + description: event.data.attributes.description, + "starts-at": event.data.attributes["starts-at"], + "ends-at": event.data.attributes["ends-at"], + "original-image-url": event.data.attributes["original-image-url"], + "logo-url": event.data.attributes["logo-url"], + timezone: Intl.DateTimeFormat().resolvedOptions().timeZone, + "is-sponsors-enabled": true + }, + id: event.data.id, + type: "event" + } + } + + await editEvent(eventData, token, event.data.id) + } + + const res = await publishSponsor(data, token); + setSponsors([...sponsors,res.data.data]) + setModalShow(false) + } catch (error) { + console.log("Error in publishing sponsor", error) + } + } + + const handleSubmit = async () => { + try { + let token = Cookies.get("event_auth"); + token + ? (token = JSON.parse(token).access_token) + : new Error("Please, Sign in again"); + + sponsors.map((value) => { + updateSponsor({data : value},token); + }) + toast.success('Sponsor Updated Successfully', { + duration: 2000, + }); + router.push(`/conferences/admin/c/${event.data.id}/sessions`) + } catch (error) { + console.log("Error in updating sponsors",error) + } + } + + const publishEvent = async () => { + try { + let token = Cookies.get("event_auth"); + token + ? (token = JSON.parse(token).access_token) + : new Error("Please, Sign in again"); + + const eventData = { + data: { + attributes: { + name: event.data.attributes.name, + description: event.data.attributes.description, + "starts-at": event.data.attributes["starts-at"], + "ends-at": event.data.attributes["ends-at"], + "original-image-url": event.data.attributes["original-image-url"], + "logo-url": event.data.attributes["logo-url"], + timezone: Intl.DateTimeFormat().resolvedOptions().timeZone, + "is-sponsors-enabled": true, + state : "published" + }, + id: event.data.id, + type: "event" + } + } + + await editEvent(eventData, token, event.data.id) + + handleSubmit(); + } catch (error) { + console.log("Error in publishing event",error) + } + } + + useEffect(() => { + const sponsorInfo = async () => { + try { + let token = Cookies.get("event_auth"); + token + ? (token = JSON.parse(token).access_token) + : new Error("Please, Sign in again"); + + const res = await getSponsorsDetails(event.data.id, token) + setSponsors(res.data.data) + } catch (e) { + console.error("An error occurred while fetching Sponsors", e); + } + }; + sponsorInfo(); + }, []) + + return ( + <> +
+ + + + setModalShow(false)} + handleAddSponsor={handleAddSponsor} + modalHandleChange={modalHandleChange} + load={load} + /> + + + + { + event.data.attributes.state === "draft" && + } + +
+ ); +}; + +const SponsorList = (props) => { + return( + + {Array.isArray(props.sponsors) && props.sponsors.length + ? props.sponsors.map((spon, id) => { + return (
+ + + + #{id + 1} + + + + + + + Name + {props.handleChange(e,id)}} + type="text" + name="name" + placeholder="Name" + defaultValue={spon.attributes.name} + /> + + + Description + {props.handleChange(e,id)}} + name="description" + as="textarea" + type="textarea" + placeholder="A short sweet biography" + defaultValue={spon.attributes.description} + /> + + + URL + {props.handleChange(e,id)}} + name="url" + placeholder="https://link-to.image" + defaultValue={spon.attributes.url} + /> + + + Logo-Url + {props.handleChange(e,id)}} + name="logo-url" + placeholder="https://link-to.image" + defaultValue={spon.attributes["logo-url"]} + /> + + + Level + {props.handleChange(e,id)}} + name="level" + placeholder="0" + defaultValue={spon.attributes.level} + min="0" + /> + Type + {props.handleChange(e,id)}} + name="type" + placeholder="Gold" + defaultValue={spon.attributes.type} + /> + + + +
+ ); + }) + : No Sponsor found} +
+ ) +} + +const SponsorModal = (props) => { + const { handleAddSponsor, modalHandleChange } = props; + return ( + + + + Add Sponsor + + +
+ + + Name + + + + Description + + + + URL + + + + Logo-Url + + + + Level + + Type + + + + + + +
+
+ ); +}; + + +export const CustomToast = ({ show, type, msg }) => { + return ( + + + Event Alert! + + {msg} + + ) +} diff --git a/app/components/conferences/admin/dashboard.js b/app/components/conferences/admin/dashboard.js index 83a2339b..14d0460d 100644 --- a/app/components/conferences/admin/dashboard.js +++ b/app/components/conferences/admin/dashboard.js @@ -69,7 +69,7 @@ export const EventDashBoard = () => { > Preview - + diff --git a/app/components/conferences/create/EventBasicDetails.js b/app/components/conferences/create/EventBasicDetails.js index e803beeb..b407ce60 100644 --- a/app/components/conferences/create/EventBasicDetails.js +++ b/app/components/conferences/create/EventBasicDetails.js @@ -17,7 +17,7 @@ import styles from "../../../styles/event.module.css"; import { EventForm } from "../eventForm"; import toast, { Toaster } from 'react-hot-toast'; -export const EventBasicCreate = ({ setDraft, handleToast }) => { +export const EventBasicCreate = ({ setDraft }) => { const [isPublic, setIsPublic] = useState(false); @@ -119,7 +119,7 @@ export const EventBasicCreate = ({ setDraft, handleToast }) => { toast.success('Event Created successfully',{ duration:2000 }) - router.push("sessions"); + router.push(`/conferences/admin/c/${res.data.data.id}/sponsors`); } catch (e) { toast.error("Event creation failed" ,{ duration:2000 diff --git a/app/components/conferences/create/EventCreate.js b/app/components/conferences/create/EventCreate.js index 5c9150c4..2d220f5a 100644 --- a/app/components/conferences/create/EventCreate.js +++ b/app/components/conferences/create/EventCreate.js @@ -11,7 +11,6 @@ export const EventCreate = ({ active }) => { const pageRoute = { "basic-detail": 0, - sessions: 1, }; useEffect(() => { @@ -33,10 +32,13 @@ export const EventCreate = ({ active }) => { Basic Details - Speakers & Session + Sponsors - Other Details + Speakers & Session + + + Other Details diff --git a/app/lib/conferences/eventCall.js b/app/lib/conferences/eventCall.js index 590f0c38..02818f12 100644 --- a/app/lib/conferences/eventCall.js +++ b/app/lib/conferences/eventCall.js @@ -138,6 +138,17 @@ export const getEventDeatils = async (eid) => { return res.json(); }; +export const getEventDeatilsWithAuth = async (eid, auth) => { + const headers = { + Accept: "application/vnd.api+json", + Authorization: `JWT ${auth}` + }; + const res = await fetch(`${eventUrl}/v1/events/${eid}?include=tickets`, { + headers: headers + }); + return res.json(); +}; + export const getAllEvents = async (eid) => { const headers = { Accept: "application/vnd.api+json", @@ -148,6 +159,53 @@ export const getAllEvents = async (eid) => { return res; }; +export const getSponsorsDetails = async (eid,auth) => { + const headers = { + Accept: "application/vnd.api+json", + Authorization: `JWT ${auth}`, + }; + const res = await axios.get(`${eventUrl}/v1/events/${eid}/sponsors`, { + headers: headers, + }); + return res; +} + +export const publishSponsor = async (data, auth) => { + const headers = { + Accept: "application/vnd.api+json", + Authorization: `JWT ${auth}`, + "Content-Type": "application/vnd.api+json", + }; + const res = await axios.post(`${eventUrl}/v1/sponsors`, data, { + headers: headers, + }); + return res; +}; + +export const deleteSponsor = async (sponsorId, auth) => { + const headers = { + Accept: "application/vnd.api+json", + Authorization: `JWT ${auth}`, + "Content-Type": "application/vnd.api+json", + }; + const res = await axios.delete(`${eventUrl}/v1/sponsors/${sponsorId}`,{ + headers: headers, + }); + return res; +}; + +export const updateSponsor = async (data, auth) => { + const headers = { + Accept: "application/vnd.api+json", + Authorization: `JWT ${auth}`, + "Content-Type": "application/vnd.api+json", + }; + const res = await axios.patch(`${eventUrl}/v1/sponsors/${data.data.id}`,data,{ + headers: headers, + }); + return res; +}; + export const getUserEventDeatils = async (uid, auth) => { const headers = { Accept: "application/vnd.api+json", diff --git a/app/pages/conferences/admin/c/[eid].js b/app/pages/conferences/admin/c/[eid]/[page].js similarity index 70% rename from app/pages/conferences/admin/c/[eid].js rename to app/pages/conferences/admin/c/[eid]/[page].js index ae8445cf..e5275386 100644 --- a/app/pages/conferences/admin/c/[eid].js +++ b/app/pages/conferences/admin/c/[eid]/[page].js @@ -1,12 +1,13 @@ import Head from "next/head"; import { Stack } from "react-bootstrap"; import { useRouter } from "next/router"; -import { IndivEventDash } from "../../../../components/conferences/admin/IndivEvent"; -import { getEventDeatils } from "../../../../lib/conferences/eventCall"; +import { IndivEventDash } from "../../../../../components/conferences/admin/IndivEvent"; +import { getEventDeatilsWithAuth } from "../../../../../lib/conferences/eventCall"; function EventEditPage({ event }) { const router = useRouter(); - const { eid } = router.query; + const { eid , page } = router.query; + return (
@@ -17,7 +18,7 @@ function EventEditPage({ event }) {
- +
@@ -37,7 +38,9 @@ export async function getServerSideProps(context) { }; } //temp 9ddffcbb - const event = await getEventDeatils(eventIdentifier); + const authToken = JSON.parse(authCookie).access_token + + const event = await getEventDeatilsWithAuth(eventIdentifier,authToken); return { props: { event },