Skip to content

Commit

Permalink
Merge pull request #504 from kunwar-11/500-adding-banner-image-and-pr…
Browse files Browse the repository at this point in the history
…ofile-picture-in-create-event-page

fix: added banner image and profile picture in event page
  • Loading branch information
jasirtp authored Nov 22, 2021
2 parents 7a2b1aa + da20bfb commit 7ea477b
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 40 deletions.
26 changes: 12 additions & 14 deletions component/admin/EventInfo.jsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { useRef, useState } from "react";
import PostService from '../../services/PostService'
import PostService from "../../services/PostService";
const EventInfo = ({ eventDetails, setEventDetails }) => {
const [fileName , setFileName] = useState("")
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)
}
if (s3ImageUrl) {
setFileName(imageFile.name);
console.log(s3ImageUrl);
setEventDetails((prev) => ({ ...prev, eventImage: s3ImageUrl }));
}
} catch (error) {
console.log(error)
console.log(error);
}
setFileName(imageFile.name)
}
};

return (
<div className="mx-10 mb-8">
Expand Down Expand Up @@ -154,12 +154,10 @@ const EventInfo = ({ eventDetails, setEventDetails }) => {
onClick={() => ref.current.click()}
>
<label htmlFor="inputFiles" className="font-bold relative">
{fileName === ""
? "Upload Image"
: fileName}
{fileName === "" ? "Upload Image" : fileName}
<input
type="file"
className="opacity-0 absolute top-0 left-0 w-full flex-grow"
className="hidden absolute top-0 left-0 w-full flex-grow"
placeholder="uplaod image"
id="inputFile"
ref={ref}
Expand Down
60 changes: 51 additions & 9 deletions component/admin/OrganizerInfo.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
import Image from "next/image";

import { useRef } from "react";
import PostService from "../../services/PostService";
const OrganizerInfo = ({ eventDetails, setEventDetails }) => {
const ref = useRef();
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);
setEventDetails((prev) => ({ ...prev, organizerImage: s3ImageUrl }));
}
} catch (error) {
console.log(error);
}
};
return (
<div className="mx-10 mb-8">
<div className="flex mb-6 items-center justify-center">
Expand All @@ -11,13 +33,33 @@ const OrganizerInfo = ({ eventDetails, setEventDetails }) => {
></div>
</div>
<div className="flex items-center">
<Image
src="/images/svgs/avatar.svg"
alt="profile image"
height={180}
width={180}
className="cursor-pointer"
/>
<div className="relative">
<img
src={`${
eventDetails.organizerImage
? eventDetails.organizerImage
: "/images/svgs/avatar.svg"
}`}
alt="profile image"
height={180}
width={180}
className="cursor-pointer rounded-full"
/>
<div onClick={() => ref.current.click()}>
<label htmlFor="inputFiles" className="font-bold relative pl-8">
Change Photo
<input
type="file"
className="hidden absolute top-0 left-0 w-full flex-grow"
placeholder="uplaod image"
id="inputFile"
ref={ref}
accept="image/*"
onChange={imageUploadHandler}
/>
</label>
</div>
</div>
<div className="flex flex-col flex-grow ml-12">
<div className="flex flex-col mb-3">
<label
Expand Down
4 changes: 3 additions & 1 deletion config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const postsUrl = `${apiVerUrl}/posts`;
const allPostsUrl = "api/posts";
const postUser = `${apiVerUrl}/posts-by-user`;
const eventsUrl = `${apiVerUrl}/events`;
const createEventUrl = `${apiVerUrl}/admin/event`;
const eventIdUrl = `${apiVerUrl}/event`;
const changeStatusUrl = "api/user/post";
const subscribeUrl = "api/subscribe";
Expand Down Expand Up @@ -53,6 +54,7 @@ const configVars = {
postsUrl,
allPostsUrl,
eventsUrl,
createEventUrl,
eventIdUrl,
changeStatusUrl,
subscribeUrl,
Expand All @@ -70,7 +72,7 @@ const configVars = {
skillUrl,
publishedPostsUrl,
// publishedPostsCountUrl,
logoutUrl,
logoutUrl
};

module.exports = configVars;
15 changes: 6 additions & 9 deletions pages/admin/create-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import notify from "../../lib/notify";
const CreateEvent = () => {
const cookies = new Cookies();
const userCookie = cookies.get("userNullcast");
console.log('cookies' , userCookie)
console.log("cookies", userCookie);
const [eventDetails, setEventDetails] = useState({
organizerImage: "",
organizerName: "",
Expand All @@ -33,20 +33,18 @@ const CreateEvent = () => {
};

const createEventHandler = async (e) => {
const eventData =
{
guest_name: eventDetails.organizerName,
const eventData = {
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",
guest_image: eventDetails.organizerImage,
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",
banner_image: eventDetails.eventImage,
description: eventDetails.description,
event_time: formatTime()
};
try {
const data = await EventService.createNewEvent(userCookie ,eventData);
const data = await EventService.createNewEvent(userCookie, eventData);
notify(data.data.message);
} catch (error) {
console.log(error);
Expand Down Expand Up @@ -94,5 +92,4 @@ const CreateEvent = () => {
);
};


export default CreateEvent;
17 changes: 10 additions & 7 deletions services/EventService.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
baseUrl,
eventsUrl,
eventIdUrl,
eventUrl
createEventUrl
} from "../config/config";
import { getUrl } from "../lib/getUrl";

Expand All @@ -30,13 +30,16 @@ async function getEventById(eventId) {
}
}

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

Expand All @@ -46,4 +49,4 @@ const EventService = {
createNewEvent
};

module.exports = EventService;
module.exports = EventService;

0 comments on commit 7ea477b

Please sign in to comment.