From 0434c2e67c4cb174467fcdb74425295cff4ad537 Mon Sep 17 00:00:00 2001 From: ayush3160 Date: Fri, 17 Feb 2023 02:24:17 +0530 Subject: [PATCH 1/4] Sponsor Form Added --- app/components/conferences/admin/EditEvent.js | 2 +- .../conferences/admin/IndivEvent.js | 169 ++++---- .../conferences/admin/SponsorForm.js | 367 ++++++++++++++++++ app/components/conferences/admin/dashboard.js | 2 +- .../conferences/create/EventBasicDetails.js | 2 +- .../conferences/create/EventCreate.js | 11 +- app/lib/conferences/eventCall.js | 50 ++- .../admin/c/{[eid].js => [eid]/[page].js} | 13 +- 8 files changed, 521 insertions(+), 95 deletions(-) create mode 100644 app/components/conferences/admin/SponsorForm.js rename app/pages/conferences/admin/c/{[eid].js => [eid]/[page].js} (70%) diff --git a/app/components/conferences/admin/EditEvent.js b/app/components/conferences/admin/EditEvent.js index 1a3b3a48..81dcb077 100644 --- a/app/components/conferences/admin/EditEvent.js +++ b/app/components/conferences/admin/EditEvent.js @@ -110,7 +110,7 @@ export const EditEvent = ({ event, handleToast }) => { sessionStorage.setItem("event", JSON.stringify(res.data)) handleToast({ show: true, msg: "Event Updated Successfully" }) - 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 a0a2864b..6e4e2a2d 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,34 +24,41 @@ import { getEventSpeakers, } from "../../../lib/conferences/eventCall"; import styles from "../../../styles/event.module.css"; -import { EditEvent , CustomToast} from "./EditEvent"; +import { EditEvent, CustomToast } from "./EditEvent"; +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({}); const [load, setLoad] = useState(false); - const [toast,setToast] = useState({show : false,msg : ''}); + const [toast, setToast] = useState({ show: false, msg: '' }); let authCookie = Cookies.get("event_auth"); if (authCookie) { 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); @@ -120,49 +128,50 @@ export const IndivEventDash = ({ eid, event }) => { return ( <> - - -

Editing Event {event.data.attributes.name}

-
- - - - -
- -
-
- -
- - - - setModalShow(false)} - handleAddSpeaker={handleAddSpeaker} - handleChange={handleChange} - load={load} - /> - -
-
- -
-
-
-
- +

Editing Event {event.data.attributes.name}

+ + + + + + {pageRoute[active] == 0 && } + {pageRoute[active] == 1 && } + {pageRoute[active] == 2 && (
+ + + + setModalShow(false)} + handleAddSpeaker={handleAddSpeaker} + handleChange={handleChange} + load={load} + /> + +
)} + {pageRoute[active] == undefined && + "Hey! You got yourself on an fabled isle."} +
+
+ ); }; @@ -190,35 +199,35 @@ const SpeakerList = ({ {Array.isArray(speakerInfo) && speakerInfo.length ? speakerInfo.map((spk) => { - return ( - - - - - - - - {spk.attributes.name} - - - - - - - - ); - }) + return ( + + + + + + + + {spk.attributes.name} + + + + + + + + ); + }) : "No Speaker found"} ); @@ -260,8 +269,8 @@ const SpeakerModal = (props) => { /> - Social links - Social links + { type="url" placeholder="GitHub" /> - + Short Biography { + + 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}); + console.log(newSponsorList) + 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); + }) + + handleToast({ show: true, msg: "Sponsor Updated Successfully" }) + router.push(`/conferences/admin/c/${event.data.id}/sessions`) + } catch (error) { + console.log("Error in updating sponsors",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) + console.log(res.data.data) + 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} + /> + + +
+ ); +}; + +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} + /> + 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 4d1dcd7f..6b75ee6c 100644 --- a/app/components/conferences/admin/dashboard.js +++ b/app/components/conferences/admin/dashboard.js @@ -60,7 +60,7 @@ export const EventDashBoard = () => { > Preview - + diff --git a/app/components/conferences/create/EventBasicDetails.js b/app/components/conferences/create/EventBasicDetails.js index c3eacf5d..f903aadd 100644 --- a/app/components/conferences/create/EventBasicDetails.js +++ b/app/components/conferences/create/EventBasicDetails.js @@ -113,7 +113,7 @@ export const EventBasicCreate = ({ setDraft, handleToast }) => { sessionStorage.setItem("draft", publish == "draft"); sessionStorage.setItem("event", JSON.stringify(res.data)); handleToast(res.data, publish); - router.push("sessions"); + router.push(`/conferences/admin/c/${res.data.data.id}/sponsors`); } catch (e) { console.error("Event create failed", e.response.data.error); if (e.response.status == 401) { diff --git a/app/components/conferences/create/EventCreate.js b/app/components/conferences/create/EventCreate.js index 2959c189..80ee506e 100644 --- a/app/components/conferences/create/EventCreate.js +++ b/app/components/conferences/create/EventCreate.js @@ -15,7 +15,6 @@ export const EventCreate = ({ active }) => { const pageRoute = { "basic-detail": 0, - sessions: 1, }; useEffect(() => { @@ -44,18 +43,18 @@ export const EventCreate = ({ active }) => { Basic Details - Speakers & Session + Sponsors - Other Details + Speakers & Session + + + Other Details {pageRoute[active] == 0 && } - {pageRoute[active] == 1 && "Coming Soon"} - {pageRoute[active] == undefined && - "Hey! You got yourself on an fabled isle."} diff --git a/app/lib/conferences/eventCall.js b/app/lib/conferences/eventCall.js index da075935..a641b925 100644 --- a/app/lib/conferences/eventCall.js +++ b/app/lib/conferences/eventCall.js @@ -139,9 +139,10 @@ export const publishEventTicket = async (data, auth) => { // Event Ticket Publish Call Ends ////// Event Fetch Call Begins -export const getEventDeatils = async (eid) => { +export const getEventDeatils = 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 @@ -157,6 +158,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..c21a67a7 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 { getEventDeatils } 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 getEventDeatils(eventIdentifier,authToken); return { props: { event }, From efb13c0e28b4e882b30526a41504a623fc346d8d Mon Sep 17 00:00:00 2001 From: ayush3160 Date: Fri, 17 Feb 2023 02:53:12 +0530 Subject: [PATCH 2/4] removed console logs --- app/components/conferences/admin/SponsorForm.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/components/conferences/admin/SponsorForm.js b/app/components/conferences/admin/SponsorForm.js index fae42de7..bfeb2570 100644 --- a/app/components/conferences/admin/SponsorForm.js +++ b/app/components/conferences/admin/SponsorForm.js @@ -52,7 +52,6 @@ export const SponsorForm = ({ event, handleToast }) => { await deleteSponsor(sponsors[index].id,token); const newSponsorList = sponsors.filter((val,id) => {return id !== index}); - console.log(newSponsorList) setSponsors(newSponsorList) } catch (error) { console.log("Error in deleting in the sponsor",error) @@ -139,7 +138,6 @@ export const SponsorForm = ({ event, handleToast }) => { : new Error("Please, Sign in again"); const res = await getSponsorsDetails(event.data.id, token) - console.log(res.data.data) setSponsors(res.data.data) } catch (e) { console.error("An error occurred while fetching Sponsors", e); From 4193064d9673fd41b436897b9ce1656eab221560 Mon Sep 17 00:00:00 2001 From: ayush3160 Date: Tue, 28 Feb 2023 00:27:22 +0530 Subject: [PATCH 3/4] Added New Event detail call with auth --- app/lib/conferences/eventCall.js | 12 +++++++++++- app/pages/conferences/admin/c/[eid]/[page].js | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/lib/conferences/eventCall.js b/app/lib/conferences/eventCall.js index a641b925..41304cdb 100644 --- a/app/lib/conferences/eventCall.js +++ b/app/lib/conferences/eventCall.js @@ -139,7 +139,17 @@ export const publishEventTicket = async (data, auth) => { // Event Ticket Publish Call Ends ////// Event Fetch Call Begins -export const getEventDeatils = async (eid, auth) => { +export const getEventDeatils = async (eid) => { + const headers = { + Accept: "application/vnd.api+json", + }; + const res = await fetch(`${eventUrl}/v1/events/${eid}?include=tickets`, { + headers: headers + }); + return res.json(); +}; + +export const getEventDeatilsWithAuth = async (eid, auth) => { const headers = { Accept: "application/vnd.api+json", Authorization: `JWT ${auth}` diff --git a/app/pages/conferences/admin/c/[eid]/[page].js b/app/pages/conferences/admin/c/[eid]/[page].js index c21a67a7..e5275386 100644 --- a/app/pages/conferences/admin/c/[eid]/[page].js +++ b/app/pages/conferences/admin/c/[eid]/[page].js @@ -2,7 +2,7 @@ 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 { getEventDeatilsWithAuth } from "../../../../../lib/conferences/eventCall"; function EventEditPage({ event }) { const router = useRouter(); @@ -40,7 +40,7 @@ export async function getServerSideProps(context) { //temp 9ddffcbb const authToken = JSON.parse(authCookie).access_token - const event = await getEventDeatils(eventIdentifier,authToken); + const event = await getEventDeatilsWithAuth(eventIdentifier,authToken); return { props: { event }, From 12901768fc2eba6335a45a83a59612400da0e511 Mon Sep 17 00:00:00 2001 From: ayush3160 Date: Tue, 28 Feb 2023 00:29:34 +0530 Subject: [PATCH 4/4] Publish Event Button Added --- .../conferences/admin/SponsorForm.js | 55 +++++++++++++++++-- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/app/components/conferences/admin/SponsorForm.js b/app/components/conferences/admin/SponsorForm.js index bfeb2570..72f1258b 100644 --- a/app/components/conferences/admin/SponsorForm.js +++ b/app/components/conferences/admin/SponsorForm.js @@ -10,7 +10,8 @@ import { Stack, ListGroup, ListGroupItem, - Modal + Modal, + ButtonGroup } from "react-bootstrap"; import Cookies from "js-cookie"; import { useRouter } from "next/router"; @@ -129,6 +130,39 @@ export const SponsorForm = ({ event, handleToast }) => { } } + 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 { @@ -163,9 +197,20 @@ export const SponsorForm = ({ event, handleToast }) => { handleChange={handleChange} handleDelete={handleDelete} /> - + + { + event.data.attributes.state === "draft" && + } + ); }; @@ -241,6 +286,7 @@ const SponsorList = (props) => { name="level" placeholder="0" defaultValue={spon.attributes.level} + min="0" /> Type { ); }) - : "No Sponsor found"} + : No Sponsor found} ) } @@ -322,6 +368,7 @@ const SponsorModal = (props) => { onChange={modalHandleChange} name="level" placeholder="0" + min="0" /> Type