diff --git a/component/admin/EventInfo.jsx b/component/admin/EventInfo.jsx index 6db42786..78db056a 100644 --- a/component/admin/EventInfo.jsx +++ b/component/admin/EventInfo.jsx @@ -1,7 +1,7 @@ import { useRef, useState } from "react"; -export default function EventInfo ({ eventDetails, setEventDetails }) { +export default function EventInfo ({ eventDetails, setEventDetails , eventDetailsError , setEventDetailsError }) { const [fileName, setFileName] = useState(""); const ref = useRef(); console.log(eventDetails?.eventImage); @@ -12,6 +12,52 @@ export default function EventInfo ({ eventDetails, setEventDetails }) { setEventDetails((prev) => ({ ...prev, eventImage: imageFile })); }; + const eventNameValidation = (e) => { + if(e.target.value === "") { + setEventDetailsError(prev => ({...prev , eventNameError : "Enter Event Name"})) + } else { + setEventDetailsError(prev => ({...prev , eventNameError : ""})) + } + } + + const eventLocationValidation = (e) => { + if(e.target.value === "") { + setEventDetailsError(prev => ({...prev , eventLocationError : "Enter Event Details"})) + } else { + setEventDetailsError(prev => ({...prev , eventLocationError : ""})) + } + } + + const eventDescriptionValidation = (e) => { + if(e.target.value === "") { + setEventDetailsError(prev => ({...prev , eventDescriptionError : "Enter Event Description"})) + } else { + setEventDetailsError(prev => ({...prev , eventDescriptionError : ""})) + } + } + + const eventLinkValidation = (e) => { + if(e.target.value === "") { + setEventDetailsError(prev => ({...prev , eventLinkError : "Enter Event Link"})) + } else { + setEventDetailsError(prev => ({...prev , eventLinkError : ""})) + } + } + + const eventDateValidation = (e) => { + if(e.target.value === "") { + setEventDetailsError(prev => ({...prev , eventDateError : "Enter Event Date"})) + } else { + setEventDetailsError(prev => ({...prev , eventDateError : ""})) + } + } + const eventTimeValidation = (e) => { + if(e.target.value === "") { + setEventDetailsError(prev => ({...prev , eventTimeError : "Enter Event Time"})) + } else { + setEventDetailsError(prev => ({...prev , eventTimeError : ""})) + } + } return (
@@ -38,7 +84,11 @@ export default function EventInfo ({ eventDetails, setEventDetails }) { eventName: e.target.value })) } + onBlur = {(e) => eventNameValidation(e)} /> + { + {eventDetailsError.eventNameError} + }
@@ -73,6 +127,7 @@ export default function EventInfo ({ eventDetails, setEventDetails }) { placeholder = "Add description here" rows="4" value={eventDetails.eventDescription} + onBlur = {(e) => eventDescriptionValidation(e)} onChange={(e) => setEventDetails((prev) => ({ ...prev, @@ -80,6 +135,9 @@ export default function EventInfo ({ eventDetails, setEventDetails }) { })) } /> + { + {eventDetailsError.eventDescriptionError} + }
@@ -108,6 +170,7 @@ export default function EventInfo ({ eventDetails, setEventDetails }) { name="event date" placeholder="choose" value={eventDetails.eventDate} + onBlur = {(e) => eventDateValidation(e)} onChange={(e) => setEventDetails((prev) => ({ ...prev, @@ -115,6 +178,9 @@ export default function EventInfo ({ eventDetails, setEventDetails }) { })) } /> + { + {eventDetailsError.eventDateError} + }
ref.current.click()} >
diff --git a/component/myblogs/WriteNav.jsx b/component/myblogs/WriteNav.jsx index 79a3c7dd..669b3567 100644 --- a/component/myblogs/WriteNav.jsx +++ b/component/myblogs/WriteNav.jsx @@ -387,13 +387,13 @@ export default function WriteNav({ className={`h-24 min-h-24 border border-dashed border-gray-400 rounded overflow-hidden relative ${!currentPost.bannerImage && "cursor-pointer" }`} > - {currentPost.bannerImage ? ( + {currentPost.banner_image ? (
{loading ? (
Loading...
) : ( banner diff --git a/courses/javascript/function.md b/courses/javascript/function.md index 2f64875a..2d71e465 100644 --- a/courses/javascript/function.md +++ b/courses/javascript/function.md @@ -43,11 +43,11 @@ testCase: ] --- -A function(a.k.a method) is basically a set of instructions that performs a certain task. It can receive inputs and can also return values to where the function has been called. +A `function`(a.k.a method) is basically a set of instructions that performs a certain task. It can receive inputs and can also return values to where the function has been called. ## Functions in JavaScript -In Javascript, a function is declared using the **“function“** keyword. For example: +In Javascript, a function is declared using the `function` keyword. For example: ```javascript function printText(text1, text2) { @@ -59,19 +59,19 @@ let str2 = "world!"; printText(str1, str2); // Hello world! ``` -From the above code snippet a function consist of: +From the above code snippet a function consist of : - The name of the function **_printText_**. -- The variables enclosed in parentheses are the parameters of that function. +- The variables enclosed in parentheses are the `parameters` of that function. - The function body enclosed in curly brackets, which contains the JavaScript statements that describes the function -- Finally we invoke the function call by the statement **_printText(str1,str2);_**. The values of _str1_ and _str2_ are copied to _text1_ and _text2_ respectively. +- Finally we invoke the function call by the statement `printText(str1,str2);`. The values of `str1` and `str2` are copied to `text1` and `text2` respectively. ## A function can return values as well -The **_return_** keyword is used to return a value from a function. Let's see an example: +The `return` keyword is used to return a value from a function. Let's see an example: ```javascript function multiplyTen(num) { @@ -83,10 +83,10 @@ console.log(num); // 50 ## Complete the task below -- create a function named **_addTwoNumbers_** with parameters **num1** and **num2**. +- create a function named `addTwoNumbers` with parameters `num1` and `num2`. -- Inside the function store **num1 + num2** to a const datatype **sum**. +- Inside the function store `num1 + num2` to a const datatype `sum`. -- The function should should return the **sum** +- The function should return the `sum` - Then print the return from the function. Pass 5 and 6 as the function arguments. diff --git a/courses/javascript/prototypes.md b/courses/javascript/prototypes.md index fbfca1e7..e40c9941 100644 --- a/courses/javascript/prototypes.md +++ b/courses/javascript/prototypes.md @@ -81,7 +81,7 @@ console.log(obj1.b); // 2 console.log(obj2.b); // undefined ``` -Here, `obj1` and `obj2` are of the same type, i.e., Object. `obj2` doesn't have the property `b`. Consider the case you want a property to have the same value accross all objects. In this case, let's say from now on, every object I create should have the property b with the value `2`. How will you solve the riddle? The answer is **`prototype`**. +Here, `obj1` and `obj2` are of the same type, i.e., Object. `obj2` doesn't have the property `b`. Consider the case you want a property to have the same value across all objects. In this case, let's say from now on, every object I create should have the property `b` with the value `2`. How will you solve the riddle? The answer is **`prototype`**. ```js Object.prototype.b = 2; @@ -115,9 +115,9 @@ console.log(human2.fullName()); // Daisy Johnson See? That's the magic of prototypes!. Now let's see what are `object prototypes`. -## Javascript provided prototypes +## JavaScript provided prototypes -Well, to make life more easier, Javascript have provided us many life saver prototypes which helps us to achieve one-line codes. You see, Javascript is a heavily Object Oriented Programming Language. Everything in Javascript revolves around object. `Array`, `Date`, and even Functions are variants of Objects, with added prototypes and properties. Let's take a look at some of the useful ones +Well, to make life more easier, JavaScript has provided us many life saver prototypes which helps us to achieve one-line codes. You see, JavaScript is a heavily Object Oriented Programming Language. Everything in JavaScript revolves around object. `Array`, `Date`, and even Functions are variants of Objects, with added prototypes and properties. Let's take a look at some of the useful ones - **`Array.prototype.push()`** - Takes 1 or more arguments, which will be pushed to the end of the array. @@ -137,8 +137,8 @@ console.log(a); // [ 3, 2, 1 ] - **`Array.prototype.slice()`** - Takes two optional arguments start and end. Default value of start and end will be 0 and length of the array. Returns a new array with items along the start to end of original array. The original array is **kept intact**. ```js -console.log(a.slice()); // [ 3, 2, 1 ] -console.log(a.slice(0, 2)); // [ 3, 2 ] +console.log(a.slice()); // [ 1, 2, 3 ] +console.log(a.slice(0, 2)); // [ 1, 2 ] ``` - **`Array.prototype.forEach()`** - Loops through the elements of the array, execute the callback function, which is provided as the argument, for the entire items of the array, one by one. @@ -149,9 +149,9 @@ a.forEach((item) => { }); /* Output- -3 -2 1 +2 +3 */ ``` @@ -162,8 +162,8 @@ console.log( a.map(item => { return item * 10; }) -); // [ 30, 20, 10 ] -console.log(a); // [ 3, 2, 1 ] +); // [ 10, 20, 30 ] +console.log(a); // [ 1, 2, 3 ] */ ``` @@ -175,7 +175,7 @@ console.log( return item % 2 === 0; // filters even values }) ); // [ 2 ] -console.log(a); // [ 3, 2, 1 ] +console.log(a); // [ 1, 2, 3 ] */ ``` @@ -190,7 +190,7 @@ console.log( third element of array as second argument*/ }) ); // 6 -console.log(a); // [ 3, 2, 1 ] +console.log(a); // [ 1, 2, 3 ] */ ``` @@ -200,8 +200,8 @@ So I hope you enjoyed this little section here. Take a break if you need warrior ## Complete the tasks below: -- Create a new constructor function Student, which accepts name and departments as params and assign to the object +- Create a new `constructor` function `Student`, which accepts `name` and `departments` as params and assign to the object -- Declare a variable student of type Student, where name is Elon and 'department' is 'ME' +- Declare a variable `student` of type `Student`, where `name` is Elon and `department` is 'ME' -- Define a new prototype isCSEstudent for Student, which is a function returning a boolean value, which will be true if the student is from department 'CSE' +- Define a new prototype `isCSEstudent` for `Student`, which is a `function` returning a boolean value, which will be `true` if the student is from department 'CSE' diff --git a/pages/admin/blogs/index.js b/pages/admin/blogs/index.js index 88e7bd82..c6b4cfb7 100644 --- a/pages/admin/blogs/index.js +++ b/pages/admin/blogs/index.js @@ -143,6 +143,8 @@ const Admin = () => { ...pagination, page, limit, + sort_field: 'updated_at', + order: 'DESC', skip: page == 1 ? 0 : (page - 1) * 10 }; setPagination(data); @@ -158,6 +160,8 @@ const Admin = () => { const data = { ...pagination, tag: tag, + sort_field: 'updated_at', + order: 'DESC', page: 1, status: status // skip: 0 @@ -183,7 +187,8 @@ const Admin = () => { * @author athulraj2002 */ const filterStatusPosts = (status) => { - const data = { ...pagination, status: status, page: 1 }; + const data = { ...pagination, status: status, page: 1, sort_field: 'updated_at', + order: 'DESC', }; setPagination((previousState) => { return { ...previousState, status: status, page: 1 }; }); diff --git a/pages/admin/events/create-event.js b/pages/admin/events/create-event.js index aaf57a1a..76dfd3a0 100644 --- a/pages/admin/events/create-event.js +++ b/pages/admin/events/create-event.js @@ -1,6 +1,7 @@ import { useEffect, useState } from "react"; import EventInfo from "../../../component/admin/EventInfo"; import OrganizerInfo from "../../../component/admin/OrganizerInfo"; +import { LoadIcon } from "../../../component/ButtonLoader/LoadIcon"; import UserService from "../../../services/UserService"; import SiteHeader from "../../../component/layout/SiteHeader/SiteHeader"; import EventService from "../../../services/EventService"; @@ -11,7 +12,6 @@ import { useRouter } from "next/router"; import SharedService from "../../../services/SharedService"; import { getCookieValue } from "../../../lib/cookie"; - export async function getServerSideProps(context) { try { if (context.req.headers.cookie) { @@ -28,7 +28,8 @@ export async function getServerSideProps(context) { if (data.roles[0] === "admin") { return { props: { - profileData: {} + profileData: {}, + referer: context.req.headers.referer ? context.req.headers.referer : "" } }; } else { @@ -75,48 +76,130 @@ export async function getServerSideProps(context) { } } -export async function getImageUrl(eventData , response) { - return Promise.all([SharedService.uploadImage(eventData.guest_image , { - stage: "dev", - fileName: eventData.guest_image.name, - id: response.data.data.id, - category: "events", - ContentType: "image/png" - }), SharedService.uploadImage(eventData.banner_image , { - stage: "dev", - fileName: eventData.banner_image.name, - id: response.data.data.id, - category: "events", - ContentType: "image/png" - })]) +export async function getImageUrl(eventData, response) { + return Promise.all([ + SharedService.uploadImage(eventData.guest_image, { + stage: "dev", + fileName: eventData.guest_image.name, + id: response.data.data.id, + category: "events", + ContentType: "image/png" + }), + SharedService.uploadImage(eventData.banner_image, { + stage: "dev", + fileName: eventData.banner_image.name, + id: response.data.data.id, + category: "events", + ContentType: "image/png" + }) + ]); } -const CreateEvent = () => { +const validateForm = (eventDetails, setEventDetailsError) => { + let isValid = false; + if (eventDetails.organizerName.trim()) { + setEventDetailsError((prev) => ({ ...prev, organizerNameError: "" })); + } else { + isValid = false; + setEventDetailsError((prev) => ({ + ...prev, + organizerNameError: "Enter Organizer's Name" + })); + } + if (eventDetails.tagLine.trim()) { + setEventDetailsError((prev) => ({ ...prev, tagLineError: "" })); + } else { + isValid = false; + setEventDetailsError((prev) => ({ + ...prev, + tagLineError: "Enter Organizer's Tag" + })); + } + if (eventDetails.eventName.trim()) { + setEventDetailsError((prev) => ({ ...prev, eventNameError: "" })); + } else { + isValid = false; + setEventDetailsError((prev) => ({ + ...prev, + eventNameError: "Enter Event Name" + })); + } + if (eventDetails.eventLocation.trim()) { + setEventDetailsError((prev) => ({ ...prev, eventLocationError: "" })); + } else { + isValid = false; + setEventDetailsError((prev) => ({ + ...prev, + eventLocationError: "Enter Event Location" + })); + } + if (eventDetails.eventDescription.trim()) { + setEventDetailsError((prev) => ({ ...prev, eventDescriptionError: "" })); + } else { + isValid = false; + setEventDetailsError((prev) => ({ + ...prev, + eventDescriptionError: "Enter Event Description" + })); + } + if (eventDetails.eventLink.trim()) { + setEventDetailsError((prev) => ({ ...prev, eventLinkError: "" })); + } else { + isValid = false; + setEventDetailsError((prev) => ({ + ...prev, + eventLinkError: "Enter Event Link" + })); + } + if (eventDetails.eventDate.trim()) { + setEventDetailsError((prev) => ({ ...prev, eventDateError: "" })); + } else { + isValid = false; + setEventDetailsError((prev) => ({ + ...prev, + eventDateError: "Enter Event Date" + })); + } + if (eventDetails.eventTime.trim()) { + setEventDetailsError((prev) => ({ ...prev, eventTimeError: "" })); + } else { + isValid = false; + setEventDetailsError((prev) => ({ + ...prev, + eventTimeError: "Enter Event Time" + })); + } + + return isValid; +}; + + +const CreateEvent = ({referer}) => { const router = useRouter() const [eventID, setEventID] = useState(router.query.id); + const [isLoading, setIsLoading] = useState(false); useEffect(() => { setTimeout(() => { - eventID && getevents(eventID); + eventID && getEvents(eventID); }, 100); }, []); - async function getevents(reqData) { + async function getEvents(reqData) { try { const data = await EventService.getEventById(reqData); - const finaldata = data.data; - const date = moment(finaldata.event_time).format('YYYY-MM-DD') - const time = moment(finaldata.event_time).format('HH:SS') - console.log(date, time) + const finalData = data.data; + const date = moment(finalData.event_time).format("YYYY-MM-DD"); + const time = moment(finalData.event_time).format("HH:SS"); setEventDetails({ - organizerImage: finaldata.guest_image, - organizerName: finaldata.guest_name, - tagLine: finaldata.guest_bio, - eventName:finaldata.title, - eventLocation:finaldata.location, - eventDescription: finaldata.description, - eventLink: finaldata.registration_link, + organizerImage: finalData.guest_image, + organizerName: finalData.guest_name, + tagLine: finalData.guest_designation, + eventName: finalData.title, + eventLocation: finalData.location, + eventDescription: finalData.description, + eventLink: finalData.registration_link, eventDate: date, eventTime: time, - eventImage: finaldata.banner_image + eventImage: finalData.banner_image }); } catch (err) { notify(err?.response?.data?.message ?? err?.message, "error"); @@ -124,7 +207,6 @@ const CreateEvent = () => { } const cookies = new Cookies(); const userCookie = cookies.get("userNullcast"); - console.log("cookies", userCookie); const [eventDetails, setEventDetails] = useState({ organizerImage: "", organizerName: "", @@ -137,37 +219,50 @@ const CreateEvent = () => { eventTime: "", eventImage: "" }); - + const [eventDetailsError, setEventDetailsError] = useState({ + organizerImageError: "", + organizerNameError: "", + tagLineError: "", + eventNameError: "", + eventLocationError: "", + eventDescriptionError: "", + eventLinkError: "", + eventDateError: "", + eventTimeError: "", + eventImageError: "" + }); const formatTime = () => { let isoDate = moment( `${eventDetails.eventDate} ${eventDetails.eventTime}` ).format(); - console.log(isoDate); return isoDate; }; - - const createEventHandler = async (e) => { const eventData = { guest_name: eventDetails.organizerName, guest_designation: eventDetails.tagLine, guest_image: eventDetails.organizerImage, title: eventDetails.eventName, - location : eventDetails.eventLocation, + location: eventDetails.eventLocation, registration_link: eventDetails.eventLink, banner_image: eventDetails.eventImage, description: eventDetails.eventDescription, event_time: formatTime() }; - try { - const data = await EventService.createNewEvent(userCookie, eventData); - notify(data.data.message); - router.push('/admin/events') - } catch (error) { - console.log(error); + if (validateForm(eventDetails, setEventDetailsError)) { + try { + setIsLoading(true); + const data = await EventService.createNewEvent(userCookie, eventData); + if (data) { + setIsLoading(false); + notify(data.data.message); + router.push("/admin/events"); + } + } catch (err) { + notify(err?.response?.data?.message ?? err?.message, "error"); + } } - formatTime(); }; const createUpdateHandler = async (e) => { @@ -182,19 +277,37 @@ const CreateEvent = () => { event_time: formatTime() }; try { - const data = await EventService.updateEvent( - userCookie, - eventData, - eventID - ); + const data = await EventService.updateEvent(eventID, eventData); notify(data.data.message); - router.push('/admin/events') - } catch (error) { - console.log(error); + router.push("/admin/events"); + } catch (err) { + notify(err?.response?.data?.message ?? err?.message, "error"); } formatTime(); }; + const clearEventHandler = (e) => { + const clearEventDetails = { + organizerImage: "", + organizerName: "", + tagLine: "", + eventName: "", + eventLocation: "", + eventDescription: "", + eventLink: "", + eventDate: "", + eventTime: "", + eventImage: "" + } + setEventDetails(clearEventDetails) + if(referer){ + router.back() + } + else{ + router.push('/admin/events') + } + } + return (
@@ -213,22 +326,32 @@ const CreateEvent = () => {
-
diff --git a/pages/login.js b/pages/login.js index e4af39ef..6821a2ea 100644 --- a/pages/login.js +++ b/pages/login.js @@ -145,7 +145,7 @@ export default function Login({ referer }) { // } else { // router.push("/"); // } - if (referer) { + if (referer.split('/')[3] !== "forgot-password") { router.back(); } else { router.push("/"); diff --git a/services/EventService.js b/services/EventService.js index 9df04827..88982373 100644 --- a/services/EventService.js +++ b/services/EventService.js @@ -5,6 +5,7 @@ import { eventIdUrl, createEventUrl } from "../config/config"; +import {getImageUrl} from '../pages/admin/events/create-event' import { getUrl } from "../lib/getUrl"; async function getLatestEvents(reqParams) { @@ -18,7 +19,7 @@ async function getLatestEvents(reqParams) { throw err; } } -async function getallevents(){ +async function getAllEvents(){ try{ const {data} = await axios.get(`${baseUrl}/api/v1/events`); return data; @@ -69,7 +70,7 @@ async function deleteEvent(eventId){ throw err; } } -async function getEventbyStatus(req){ +async function getEventByStatus(req){ try{ const {data} = await axios.get(`${baseUrl}/v1/events?status=${req.status}`) return data @@ -79,7 +80,7 @@ async function getEventbyStatus(req){ } } -async function updateEvent(updatedData , eventId) { +async function updateEvent(eventId, updatedData) { try { const response = await axios.put(`${baseUrl}/${createEventUrl}/${eventId}`,updatedData) if(response){ @@ -94,9 +95,9 @@ const EventService = { getLatestEvents, getEventById, createNewEvent, - getallevents, + getAllEvents, deleteEvent, - getEventbyStatus, + getEventByStatus, updateEvent };