Skip to content

Commit

Permalink
feat: create event is created some bugs needed to be fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhkunwar11 committed Nov 15, 2021
1 parent 5ff783c commit 4b08c07
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 14 deletions.
39 changes: 30 additions & 9 deletions component/admin/EventInfo.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
import { useRef } from "react";
import { useRef, useState } from "react";
import PostService from '../../services/PostService'
const EventInfo = ({ eventDetails, setEventDetails }) => {
const [fileName , setFileName] = useState("")
const ref = useRef();
console.log(eventDetails?.eventImage);

const imageUploadHandler = async (e) => {

const imageFile = e.target.files[0];

const imageData = {
stage: "dev",
fileName: imageFile.name,
category: "events",
ContentType: imageFile.type
}

try {
const s3ImageUrl = await PostService.uploadImage(imageFile, imageData);

if(s3ImageUrl){
console.log(s3ImageUrl)
}
} catch (error) {
console.log(error)
}
setFileName(imageFile.name)
}

return (
<div className="mx-10 mb-8">
<div className="flex mb-6 items-center justify-center">
Expand Down Expand Up @@ -128,22 +154,17 @@ const EventInfo = ({ eventDetails, setEventDetails }) => {
onClick={() => ref.current.click()}
>
<label htmlFor="inputFiles" className="font-bold relative">
{eventDetails?.eventImage === ""
{fileName === ""
? "Upload Image"
: eventDetails?.eventImage?.name}
: fileName}
<input
type="file"
className="opacity-0 absolute top-0 left-0 w-full flex-grow"
placeholder="uplaod image"
id="inputFile"
ref={ref}
accept="image/*"
onChange={(e) =>
setEventDetails((prev) => ({
...prev,
eventImage: e.target.files[0]
}))
}
onChange={imageUploadHandler}
/>
</label>
</div>
Expand Down
1 change: 1 addition & 0 deletions component/admin/OrganizerInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const OrganizerInfo = ({ eventDetails, setEventDetails }) => {
alt="profile image"
height={180}
width={180}
className="cursor-pointer"
/>
<div className="flex flex-col flex-grow ml-12">
<div className="flex flex-col mb-3">
Expand Down
4 changes: 3 additions & 1 deletion config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const loginUrl = `${apiVerUrl}/signin`;
const signUpUrl = `${apiVerUrl}/user`;
const userUrl = `${apiVerUrl}/user`;
const usersUrl = `${apiVerUrl}/users`;
const adminUrl = "api/admin";
const adminUrl = `${apiVerUrl}/admin`;
const eventUrl = `${apiVerUrl}/admin/event`;
const tagUrl = `${apiVerUrl}/tags`;
const postTagUrl = `${apiVerUrl}/post-tag`;
const postTagsUrl = `${apiVerUrl}/post-tags`;
Expand All @@ -43,6 +44,7 @@ const configVars = {
clientUrl,
s3Url,
authUrl,
eventUrl,
enrolUrl,
postUrl,
postBySlug,
Expand Down
76 changes: 75 additions & 1 deletion pages/admin/create-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,48 @@ import { useState } from "react";
import EventInfo from "../../component/admin/EventInfo";
import OrganizerInfo from "../../component/admin/OrganizerInfo";
import SiteHeader from "../../component/layout/SiteHeader/SiteHeader";
import EventService from "../../services/EventService";
import moment from "moment";
import Cookies from "universal-cookie";


// export async function getServerSideProps(context) {
// console.log('from server:-' , context.req.headers.cookie)
// try {
// if (context.req.headers.cookie) {
// const contextCookie = getCookieValue(
// context.req.headers.cookie,
// "userNullcast"
// );
// if (contextCookie) {
// const cookie = JSON.parse(contextCookie)
// return {
// props : {

// }
// }
// } else {
// return {
// props : {

// }
// }
// };
// }
// } catch (err) {
// //notify(err?.response?.data?.message ?? err?.message, 'error');
// return {
// props : {

// }
// }
//}}


const CreateEvent = () => {
const cookies = new Cookies();
const userCookie = cookies.get("userNullcast");
console.log('cookies' , userCookie)
const [eventDetails, setEventDetails] = useState({
organizerImage: "",
organizerName: "",
Expand All @@ -17,6 +57,35 @@ const CreateEvent = () => {
eventImage: ""
});

const formatTime = () => {
let isoDate = moment(
`${eventDetails.eventDate} ${eventDetails.eventTime}`
).format();
console.log(isoDate);
return isoDate;
};

const createEventHandler = async (e) => {
//e.preventDefault();
try {
const data = await EventService.createNewEvent(userCookie , {
guest_name: eventDetails.organizerName,
guest_designation: eventDetails.tagLine,
guest_image: "https://upload.wikimedia.org/wikipedia/commons/thumb/8/8e/Nextjs-logo.svg/1200px-Nextjs-logo.svg.png",
title: eventDetails.eventName,
registration_link: eventDetails.eventLink,
banner_image:
"https://upload.wikimedia.org/wikipedia/commons/thumb/8/8e/Nextjs-logo.svg/1200px-Nextjs-logo.svg.png",
description: eventDetails.description,
event_time: formatTime()
});
console.log(data);
} catch (error) {
console.log(error);
}
formatTime();
};

return (
<div className="bg-gray-100 min-h-full pb-5">
<SiteHeader />
Expand Down Expand Up @@ -44,7 +113,11 @@ const CreateEvent = () => {
<button className="border-2 border-black bg-white px-8 py-2 rounded mr-5">
Cancel
</button>
<button className="border-2 border-black bg-black px-8 py-2 rounded text-white">
<button
className="border-2 border-black bg-black px-8 py-2 rounded text-white"
onClick={(e) => createEventHandler(e)}
type="button"
>
Donate
</button>
</div>
Expand All @@ -53,4 +126,5 @@ const CreateEvent = () => {
);
};


export default CreateEvent;
16 changes: 14 additions & 2 deletions services/EventService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const axios = require("axios");
import {
baseUrl,
eventsUrl,
eventIdUrl
eventIdUrl,
eventUrl
} from "../config/config";
import { getUrl } from "../lib/getUrl";

Expand All @@ -29,9 +30,20 @@ async function getEventById(eventId) {
}
}

async function createNewEvent(userCookie ,eventData) {
try {
const response = await axios.post(`${baseUrl}/${eventUrl}` , eventData)
return response
} catch (err) {
console.log(err);
throw err;
}
}

const EventService = {
getLatestEvents,
getEventById
getEventById,
createNewEvent
};

module.exports = EventService;
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3308,7 +3308,7 @@ modern-normalize@^1.0.0:

moment@^2.29.1:
version "2.29.1"
resolved "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.1.tgz#b2be769fa31940be9eeea6469c075e35006fa3d3"
integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==

[email protected]:
Expand Down Expand Up @@ -5113,6 +5113,11 @@ yargs@^17.0.0:
y18n "^5.0.5"
yargs-parser "^20.2.2"

yarn@^1.22.17:
version "1.22.17"
resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.22.17.tgz#bf910747d22497b573131f7341c0e1d15c74036c"
integrity sha512-H0p241BXaH0UN9IeH//RT82tl5PfNraVpSpEoW+ET7lmopNC61eZ+A+IDvU8FM6Go5vx162SncDL8J1ZjRBriQ==

[email protected]:
version "0.1.2"
resolved "https://registry.yarnpkg.com/yeast/-/yeast-0.1.2.tgz#008e06d8094320c372dbc2f8ed76a0ca6c8ac419"
Expand Down

0 comments on commit 4b08c07

Please sign in to comment.