From b2abecad092135381d15117927c568608617b08c Mon Sep 17 00:00:00 2001 From: Austin Asoluka Date: Tue, 23 May 2023 21:20:12 +0100 Subject: [PATCH] consume APIs for assigned tasks and remove all console log from codebase --- frontend/mms-Admin/components/AddMentor.js | 110 ++--- .../mms-Admin/components/ChatComponent.js | 404 +++++++++--------- frontend/mms-Admin/components/CustomModal.js | 2 +- .../Layout/BroadcastMessage/index.jsx | 1 - .../mms-Admin/components/Layout/Layout.jsx | 51 +-- frontend/mms-Admin/components/TasksSidebar.js | 134 +++--- .../mms-Admin/components/atoms/Button.jsx | 2 +- .../components/molecules/Selector.jsx | 20 +- .../components/organisms/Certificate.jsx | 4 +- .../mms-Admin/components/settings/General.js | 5 +- .../components/settings/Notifications.js | 145 ++++--- .../mms-Admin/components/settings/Password.js | 8 +- .../mms-Admin/components/settings/Support.js | 9 +- frontend/mms-Admin/hooks/usePostFetch.js | 9 +- frontend/mms-Admin/lib/fetch-wrapper.js | 2 +- frontend/mms-Admin/pages/_app.js | 4 +- frontend/mms-Admin/pages/api/program/index.js | 9 +- frontend/mms-Admin/pages/api/report/index.js | 11 + frontend/mms-Admin/pages/api/task/index.js | 5 +- .../mms-Admin/pages/api/taskReport/index.js | 4 +- .../mms-Admin/pages/discussion-forum/[id].js | 3 - frontend/mms-Admin/pages/hh.js | 22 +- .../pages/mentors/programs/[mentorID].js | 204 ++++----- .../pages/mentors/tasks/[mentorID].js | 3 +- frontend/mms-Admin/pages/programs/[action].js | 224 ++++++++++ frontend/mms-Admin/pages/programs/create.jsx | 155 ------- frontend/mms-Admin/pages/programs/index.jsx | 60 +-- frontend/mms-Admin/pages/reports.jsx | 111 ++--- frontend/mms-Admin/pages/tasks/[action].js | 215 ++++++++++ frontend/mms-Admin/pages/tasks/[id].js | 233 ---------- .../{[id]/assignees.js => assignees/[id].js} | 0 frontend/mms-Admin/pages/tasks/create.js | 244 ----------- frontend/mms-Admin/pages/tasks/index.js | 260 +++++------ .../mms-Admin/services/broadcast.service.js | 3 +- frontend/mms-Admin/styles/reports.module.scss | 1 - 35 files changed, 1219 insertions(+), 1458 deletions(-) create mode 100644 frontend/mms-Admin/pages/api/report/index.js create mode 100644 frontend/mms-Admin/pages/programs/[action].js delete mode 100644 frontend/mms-Admin/pages/programs/create.jsx create mode 100644 frontend/mms-Admin/pages/tasks/[action].js delete mode 100644 frontend/mms-Admin/pages/tasks/[id].js rename frontend/mms-Admin/pages/tasks/{[id]/assignees.js => assignees/[id].js} (100%) delete mode 100644 frontend/mms-Admin/pages/tasks/create.js diff --git a/frontend/mms-Admin/components/AddMentor.js b/frontend/mms-Admin/components/AddMentor.js index 6abffff9..6925f606 100644 --- a/frontend/mms-Admin/components/AddMentor.js +++ b/frontend/mms-Admin/components/AddMentor.js @@ -2,20 +2,16 @@ import React, { useState } from "react"; import { Modal } from "antd"; import styles from "./componentStyles/splashscreen.module.css"; import { CustomButton, CustomInput } from "./formInputs/CustomInput"; -import toast from 'react-hot-toast'; +import toast from "react-hot-toast"; import { inviteMentor } from "pages/api/user"; -import AddMentorSuccess from "./AddMentorSuccess" +import AddMentorSuccess from "./AddMentorSuccess"; -function AddMentor({ - message, - isOpen, - setIsOpen, -}) { +function AddMentor({ message, isOpen, setIsOpen }) { const [formData, setFormData] = useState({ - firstName: '', - lastName: '', - email: '', - roleId: 2 + firstName: "", + lastName: "", + email: "", + roleId: 2, }); const [open, setOpen] = useState(false); const [loading, setLoading] = useState(false); @@ -28,26 +24,31 @@ function AddMentor({ setOpen(true); }; - const validateForm = () => { - if (formData.firstName.length < 4 || formData.email.length < 4 || formData.lastName.length < 4 ) { - window.alert('First name, Last name and email must be at least 4 characters long.'); + if ( + formData.firstName.length < 4 || + formData.email.length < 4 || + formData.lastName.length < 4 + ) { + window.alert( + "First name, Last name and email must be at least 4 characters long.", + ); return false; } return true; }; - + const InviteMentor = async () => { setLoading(true); try { const isFormValid = validateForm(); if (!isFormValid) return; - + const response = await inviteMentor(formData); - console.log(response) + if (response.status === 202) { toast.success(response?.data?.message); - handleInvite() + handleInvite(); setLoading(false); } } catch (e) { @@ -55,11 +56,11 @@ function AddMentor({ toast.error(e); } }; - const handleInviteMentor = event => { + const handleInviteMentor = (event) => { const { name, value } = event.target; - setFormData(prevState => ({ + setFormData((prevState) => ({ ...prevState, - [name]: value + [name]: value, })); }; @@ -78,41 +79,48 @@ function AddMentor({

{message}

-
-
-
- +
+
+
+ +
+
+ +
-
- -
- -
-
- Cancel - Send -
+
+ + Cancel + + + Send + +
{open && ( diff --git a/frontend/mms-Admin/components/ChatComponent.js b/frontend/mms-Admin/components/ChatComponent.js index 24bde608..3cbe100a 100644 --- a/frontend/mms-Admin/components/ChatComponent.js +++ b/frontend/mms-Admin/components/ChatComponent.js @@ -1,21 +1,24 @@ -import React, { useState, useRef, useEffect } from 'react' +import React, { useState, useRef, useEffect } from "react"; import styles from "./componentStyles/chatcomponent.module.css"; -import { CustomInput } from './formInputs/CustomInput'; -import EmojiPicker from 'emoji-picker-react'; +import { CustomInput } from "./formInputs/CustomInput"; +import EmojiPicker from "emoji-picker-react"; import Pusher from "pusher-js"; -import Icon from './Icon'; -import { authChatChannel, authChatUser, saveChat, getAllChat } from "pages/api/chat"; +import Icon from "./Icon"; +import { + authChatChannel, + authChatUser, + saveChat, + getAllChat, +} from "pages/api/chat"; import moment from "moment"; -import { useLogin } from '../hooks/useLogin'; +import { useLogin } from "../hooks/useLogin"; import { convertToURLQuery } from "utils/extractTitleFromUrl"; -import NoSSRWrapper from "../components/DisableSSR" +import NoSSRWrapper from "../components/DisableSSR"; - - -function ChatComponent({receiverId,isModelChatClose}) { +function ChatComponent({ receiverId, isModelChatClose }) { const [messages, setMessages] = useState([]); const [isMobile, setIsMobile] = useState(false); - const [message, setMessage] = useState(''); + const [message, setMessage] = useState(""); const [selectedfile, setSelectedFile] = useState(null); const [fileName, setFileName] = useState(""); const fileInput = useRef(null); @@ -24,246 +27,243 @@ function ChatComponent({receiverId,isModelChatClose}) { const [limit, setLimit] = useState(10); const [maxPage, setMaxPage] = useState(null); const containerRef = useRef(null); - const {user} = useLogin() + const { user } = useLogin(); let allMessages = []; const today = new Date().toLocaleDateString(); - React.useEffect(() => { - const mediaQuery = window.matchMedia("(max-width: 992px)"); - setIsMobile(mediaQuery.matches); - }, []); + React.useEffect(() => { + const mediaQuery = window.matchMedia("(max-width: 992px)"); + setIsMobile(mediaQuery.matches); + }, []); - const pusher = new Pusher(process.env.NEXT_PUBLIC_PUSHER_APP_KEY, { - // userAuthentication: { - // endpoint: authChatUser, - // }, - // channelAuthorization: { - // endpoint: authChatChannel, - // }, - cluster: 'eu' - }); + const pusher = new Pusher(process.env.NEXT_PUBLIC_PUSHER_APP_KEY, { + // userAuthentication: { + // endpoint: authChatUser, + // }, + // channelAuthorization: { + // endpoint: authChatChannel, + // }, + cluster: "eu", + }); + + useEffect(() => { + setMessages([]); // clear the messages state when receiverId changes + }, [receiverId]); + + const formData = new FormData(); - useEffect(() => { - setMessages([]); // clear the messages state when receiverId changes - }, [receiverId]); - - const formData = new FormData(); - - let channelName = ''; - if (receiverId) { - channelName = `${receiverId}-${user?.id}`; - if (selectedfile === null){ - const payload = { message, senderId: user?.id, channelName, recipientId:receiverId }; - for (const key in payload) { - if (payload[key]) { - formData.append(key, payload[key]); - } + let channelName = ""; + if (receiverId) { + channelName = `${receiverId}-${user?.id}`; + if (selectedfile === null) { + const payload = { + message, + senderId: user?.id, + channelName, + recipientId: receiverId, + }; + for (const key in payload) { + if (payload[key]) { + formData.append(key, payload[key]); } } - if (selectedfile !== null){ - const payload = { message, senderId: user?.id, channelName, recipientId:receiverId, imageUrl:selectedfile }; - for (const key in payload) { - if (payload[key]) { - formData.append(key, payload[key]); - } + } + if (selectedfile !== null) { + const payload = { + message, + senderId: user?.id, + channelName, + recipientId: receiverId, + imageUrl: selectedfile, + }; + for (const key in payload) { + if (payload[key]) { + formData.append(key, payload[key]); } } - } + } - + const loadChat = async () => { + // const payload = { senderId: user?.id, recipientId:receiverId, page, limit }; + const senderId = user?.id; + const recipientId = receiverId; + try { + const response = await getAllChat(senderId, recipientId); + // setMessages(response?.data?.messages?.data) + const newItems = response?.data?.messages?.data ?? []; + setMessages((prevItems) => [...prevItems, ...newItems]); + setMaxPage(response?.data?.messages?.meta?.last_page ?? maxPage); + } catch (e) {} + }; + useEffect(() => { + if (!receiverId) { + return; + } + loadChat(); + }, [receiverId]); - const loadChat = async () => { - // const payload = { senderId: user?.id, recipientId:receiverId, page, limit }; - const senderId = user?.id - const recipientId = receiverId - try{ - const response = await getAllChat(senderId,recipientId) - // console.log(response?.data?.messages?.meta) - // setMessages(response?.data?.messages?.data) - const newItems = response?.data?.messages?.data ?? []; - setMessages(prevItems => [...prevItems, ...newItems]); - setMaxPage(response?.data?.messages?.meta?.last_page ?? maxPage); - // console.log(response) + const handleScroll = () => { + const element = containerRef.current; + if (!element) return; + const { scrollTop, scrollHeight, clientHeight } = element; + if (scrollTop + clientHeight >= scrollHeight) { + setPage((prevPage) => prevPage + 1); + } else if (scrollTop === 0 && page > 1) { + setPage((prevPage) => prevPage - 1); + } + }; - } catch (e) { - console.log(e) - } - }; - useEffect(() => { - if (!receiverId) { - return; - } - loadChat() - }, [receiverId]) - - const handleScroll = () => { - const element = containerRef.current; - if (!element) return; - const { scrollTop, scrollHeight, clientHeight } = element; - if (scrollTop + clientHeight >= scrollHeight) { - setPage(prevPage => prevPage + 1); - } else if (scrollTop === 0 && page > 1) { - setPage(prevPage => prevPage - 1); - } + useEffect(() => { + const element = containerRef.current; + if (element) element.addEventListener("scroll", handleScroll); + return () => { + if (element) element.removeEventListener("scroll", handleScroll); }; - + }, [messages]); - useEffect(() => { - const element = containerRef.current; - if (element) element.addEventListener('scroll', handleScroll); - return () => { - if (element) element.removeEventListener('scroll', handleScroll); - }; - - }, [messages]); + useEffect(() => { + if (!receiverId) { + return; + } + Pusher.logToConsole = true; + const channel = pusher.subscribe(channelName); + channel.bind(channelName, (data) => { + // allMessages.push(data?.chat); + // setMessages(allMessages); - useEffect(() => { - if (!receiverId) { - return; - } - Pusher.logToConsole = true; - const channel = pusher.subscribe(channelName); - channel.bind(channelName, (data) => { - // allMessages.push(data?.chat); - // setMessages(allMessages); - console.log(data) - setMessages((prevState) => [ - ...prevState,data?.chat, - ]); - }); + setMessages((prevState) => [...prevState, data?.chat]); + }); }, [receiverId]); - - const handleFileChange = (event) => { - const file = event.target.files[0]; - setSelectedFile(file); - setFileName(file?.name); - }; + const handleFileChange = (event) => { + const file = event.target.files[0]; + setSelectedFile(file); + setFileName(file?.name); + }; - const [showPicker, setShowPicker] = useState(false); - - const onEmojiClick = (emoji) => { - setMessage(prevInput => prevInput + emoji.emoji); - setShowPicker(false); - }; + const [showPicker, setShowPicker] = useState(false); + + const onEmojiClick = (emoji) => { + setMessage((prevInput) => prevInput + emoji.emoji); + setShowPicker(false); + }; - const handleKeyDown = async (event) => { + const handleKeyDown = async (event) => { if (event.key === "Enter" && event.shiftKey) { setMessage((prevInput) => prevInput + "\n"); } else if (event.key === "Enter") { - event.preventDefault(); - try{ - const response = await saveChat(receiverId, formData) - // console.log(response) - } catch (e) { - console.log(e) - } - finally { - setMessage('') - setSelectedFile(null) - setFileName('') - } - + event.preventDefault(); + try { + const response = await saveChat(receiverId, formData); + } catch (e) { + } finally { + setMessage(""); + setSelectedFile(null); + setFileName(""); + } } }; - - useEffect(() => { - chatBoxRef.current.scrollIntoView({ behavior: 'smooth' }); + chatBoxRef.current.scrollIntoView({ behavior: "smooth" }); }, [messages]); return ( -
-
- {isMobile ? ( - - - - ): ""} +
+
+ {isMobile ? ( + + + + ) : ( + "" + )} -
-
- Conversation Started, {moment(today).format("DD MMM")} -
-
-
- {messages.length > 0 ? ( - messages.map((msg) => ( +
+
+ + Conversation Started, {moment(today).format("DD MMM")} + +
+
+
+ {messages.length > 0 ? ( + messages.map((msg) => ( <> -
-
{msg?.message}
-
{moment(msg?.sent_at).format('lll')}
-
+
+
{msg?.message}
+
+ {moment(msg?.sent_at).format("lll")} +
+
)) - ): ( - - <> -
- Select a user to chat with -
- - )} -
-
- <> -
+ ) : ( + <> +
Select a user to chat with
+ + )} +
+
+ <> +
-
setShowPicker(val => !val)}> +
setShowPicker((val) => !val)}>
-
fileInput.current.click()}> +
fileInput.current.click()}> - {fileName && {fileName}}
- setMessage(e.target.value)} - className={styles.input_chat} - placeholder="Type a message..." - onKeyDown={handleKeyDown} - /> + setMessage(e.target.value)} + className={styles.input_chat} + placeholder="Type a message..." + onKeyDown={handleKeyDown} + />
-
-
- {showPicker && } -
+
+
+ {showPicker && } +
+
-
- ) + ); } -export default ChatComponent - - - +export default ChatComponent; diff --git a/frontend/mms-Admin/components/CustomModal.js b/frontend/mms-Admin/components/CustomModal.js index c07fff0d..ad6350d8 100644 --- a/frontend/mms-Admin/components/CustomModal.js +++ b/frontend/mms-Admin/components/CustomModal.js @@ -55,7 +55,7 @@ export const CustomFormModal = ({ const handleSubmit = async (event) => { //call api here event.preventDefault(); - console.log(postData); + try { if (!postData.title || !postData.description) { setConfirmLoading(false); diff --git a/frontend/mms-Admin/components/Layout/BroadcastMessage/index.jsx b/frontend/mms-Admin/components/Layout/BroadcastMessage/index.jsx index 6afba35b..57d9faae 100644 --- a/frontend/mms-Admin/components/Layout/BroadcastMessage/index.jsx +++ b/frontend/mms-Admin/components/Layout/BroadcastMessage/index.jsx @@ -31,7 +31,6 @@ const BroadcastMessageScreen = () => { const loadUsersCallback = useCallback(loadUsers, []); const onSearch = (query) => { - console.log("Search:", query); ref.current = query; setLoading(!!query); setUsers([]); diff --git a/frontend/mms-Admin/components/Layout/Layout.jsx b/frontend/mms-Admin/components/Layout/Layout.jsx index dacfbfcb..2b1d1477 100644 --- a/frontend/mms-Admin/components/Layout/Layout.jsx +++ b/frontend/mms-Admin/components/Layout/Layout.jsx @@ -115,7 +115,7 @@ const AppLayout = ({ children }) => { const loadTask = async () => { const query = { search: searchTask, page: pageNumber, limit }; - console.log(query); + try { setLoading(true); const { data } = await fetchTasks(convertToURLQuery(query)); @@ -159,55 +159,6 @@ const AppLayout = ({ children }) => { /> )} - {router?.pathname === "/tasks" && ( - <> - {showMentorSearch !== false ? ( - - ) : ( - "" - )} -
-
- -
-
- -
-
-
- -
- - router.push("/broadcast")}> - Send Broadcast Message - - - - )} {router?.pathname === "/messages" && ( <>
diff --git a/frontend/mms-Admin/components/TasksSidebar.js b/frontend/mms-Admin/components/TasksSidebar.js index 96a35e67..becdc074 100644 --- a/frontend/mms-Admin/components/TasksSidebar.js +++ b/frontend/mms-Admin/components/TasksSidebar.js @@ -14,49 +14,45 @@ function TasksSidebar(props) { const [limit, setLimit] = useState(10); const [items, setItems] = useState([]); const [data, setData] = useState(null); - const [loading, setLoading] = useState(false) + const [loading, setLoading] = useState(false); const containerRef = useRef(null); - const [ {taskSearch} ] = Object.values(useStateValue()) - console.log(taskSearch) + const [{ taskSearch }] = Object.values(useStateValue()); const loadMore = async () => { - const query = { page, limit } + const query = { page, limit }; try { dispatch({ - type: 'TASK_SEARCH', - payload: query - }) + type: "TASK_SEARCH", + payload: query, + }); } catch (error) {} }; - useEffect(() => { - loadMore() - }, [page]) + loadMore(); + }, [page]); const handleScroll = () => { const element = containerRef.current; if (!element) return; const { scrollTop, scrollHeight, clientHeight } = element; if (scrollTop + clientHeight >= scrollHeight) { - setPage(prevPage => prevPage + 1); + setPage((prevPage) => prevPage + 1); } else if (scrollTop === 0 && page > 1) { - setPage(prevPage => prevPage - 1); + setPage((prevPage) => prevPage - 1); } }; - - + useEffect(() => { const element = containerRef.current; - if (element) element.addEventListener('scroll', handleScroll); + if (element) element.addEventListener("scroll", handleScroll); return () => { - if (element) element.removeEventListener('scroll', handleScroll); + if (element) element.removeEventListener("scroll", handleScroll); }; - }, []); const [isMobile, setIsMobile] = useState(false); const [isModalOpen, setIsModalOpen] = useState(false); - + React.useEffect(() => { const mediaQuery = window.matchMedia("(max-width: 992px)"); setIsMobile(mediaQuery.matches); @@ -71,11 +67,10 @@ function TasksSidebar(props) { setIsModalOpen(true); }; - const handleCombinedActions = (itemId, item) => { handleData(item); handleClick(); - } + }; const handleData = (item) => { setData(item); @@ -84,39 +79,47 @@ function TasksSidebar(props) { return (
- { taskSearch?.data?.length > 0 ? ( - taskSearch?.data?.map(item => ( - <> -
-
handleCombinedActions(item.id, item)}> - -
-
handleCombinedActions(item.id, item)}> -

- {item.title.slice(0, 29)}... -

-
+ {taskSearch?.data?.length > 0 ? ( + taskSearch?.data?.map((item) => ( + <> +
+
handleCombinedActions(item.id, item)}> -
{moment(item.endDate).diff(moment(), 'days')} days from now
+ icon={"/assets/images/task.svg"} + width={"40px"} + height={"40px"} + /> +
+
handleCombinedActions(item.id, item)}> +

{item.title.slice(0, 29)}...

+
+ +
+ {moment(item.endDate).diff(moment(), "days")} days from now +
+
-
- {isModalOpen && isMobile && } + {isModalOpen && isMobile && ( + + )}
)) @@ -144,25 +147,24 @@ function TasksSidebar(props) {
- ) - } + )}
- ) + ); } -export default TasksSidebar +export default TasksSidebar; // axios.get(`task?page=${currentPage}&limit=${pageSize}`, { - // headers: { - // 'Authorization': `Bearer ${token}` - // } - // }) - // .then(response => { - // setData(response?.data?.data); - // const newItems = response?.data?.data; - // setItems(newItems); - // setCurrentPage(currentPage + 1); - // }) - // .catch(error => { - // console.error('Error loading more items:', error); - // }); \ No newline at end of file +// headers: { +// 'Authorization': `Bearer ${token}` +// } +// }) +// .then(response => { +// setData(response?.data?.data); +// const newItems = response?.data?.data; +// setItems(newItems); +// setCurrentPage(currentPage + 1); +// }) +// .catch(error => { +// console.error('Error loading more items:', error); +// }); diff --git a/frontend/mms-Admin/components/atoms/Button.jsx b/frontend/mms-Admin/components/atoms/Button.jsx index 1a929a9c..e28b8e7f 100644 --- a/frontend/mms-Admin/components/atoms/Button.jsx +++ b/frontend/mms-Admin/components/atoms/Button.jsx @@ -40,7 +40,7 @@ export const Button = (props) => { if (props.type === "link") return ( - + + {type === "link" ? ( + + + + ) : ( + + )}
); diff --git a/frontend/mms-Admin/components/organisms/Certificate.jsx b/frontend/mms-Admin/components/organisms/Certificate.jsx index e00afd06..545fdf77 100644 --- a/frontend/mms-Admin/components/organisms/Certificate.jsx +++ b/frontend/mms-Admin/components/organisms/Certificate.jsx @@ -30,9 +30,7 @@ const Certificate = ({ }); }, [ref]); - const handleChange = (value) => { - console.log(`selected ${value}`); - }; + const handleChange = (value) => {}; return ( <> diff --git a/frontend/mms-Admin/components/settings/General.js b/frontend/mms-Admin/components/settings/General.js index f48d7146..d458ead6 100644 --- a/frontend/mms-Admin/components/settings/General.js +++ b/frontend/mms-Admin/components/settings/General.js @@ -67,7 +67,6 @@ function General() { const handleSubmit = async (e) => { e.preventDefault(); - console.log(file); setLoading(true); const valid = validateInputs(profileData); if (valid) { @@ -76,7 +75,6 @@ function General() { try { const { bio, website } = profileData; if (file) { - console.log("here"); formData.append("profileImagePath", file); } formData.append("bio", bio); @@ -84,10 +82,9 @@ function General() { formData.append("socialMediaLinks", JSON.stringify(sMedia)); formData.append("country", country); formData.append("city", region); - const response = await updateUserProfile(formData); - console.log(response); + if (response.status === 200) { setSuccess(true); } diff --git a/frontend/mms-Admin/components/settings/Notifications.js b/frontend/mms-Admin/components/settings/Notifications.js index 34e8d263..41201d62 100644 --- a/frontend/mms-Admin/components/settings/Notifications.js +++ b/frontend/mms-Admin/components/settings/Notifications.js @@ -1,45 +1,47 @@ import React, { useState, useEffect } from "react"; import styles from "../componentStyles/notifications.module.css"; -import ToggleInput from "components/ToggleInput"; -import { fetchNotificationSettings , updateNotificationSettings } from "pages/api/setting"; +import ToggleInput from "components/ToggleInput"; +import { + fetchNotificationSettings, + updateNotificationSettings, +} from "pages/api/setting"; import { Loader } from "components/Loader"; import debounce from "lodash.debounce"; import { useStateValue } from "store/context"; import SuccessMessage from "components/SuccessMessage"; function Notifications() { - const generalInputFields = [ { name: "all", label: "All Notifications", email: "email", - push: "push" + push: "push", }, { name: "programs", label: "Programs", email: "email", - push: "push" + push: "push", }, { name: "tasks", label: "Tasks", email: "email", - push: "push" + push: "push", }, { name: "approval_requests", label: "Approval Requests", email: "email", - push: "push" + push: "push", }, { name: "reports", label: "Reports", email: "email", - push: "push" - } + push: "push", + }, ]; const discussionInputFields = [ @@ -47,32 +49,32 @@ function Notifications() { name: "comments_on_post", label: "Comments on post", email: "email", - push: "push" + push: "push", }, { name: "posts", label: "Posts", email: "email", - push: "push" + push: "push", }, { name: "comments", label: "Comments", email: "email", - push: "push" + push: "push", }, { name: "mentions", label: "Mentions", email: "email", - push: "push" + push: "push", }, { name: "direct_message", label: "Direct Message", email: "email", - push: "push" - } + push: "push", + }, ]; const [settings, setSettings] = useState({}); @@ -80,30 +82,32 @@ function Notifications() { const [_, dispatch] = Object.values(useStateValue()); const [loading, setLoading] = useState(false); const [modalOpen, setModalOpen] = useState(false); - + const loadNotificationSettings = async () => { - setLoading(true) + setLoading(true); try { - setLoading(true) - const { data: {settings} } = await fetchNotificationSettings() + setLoading(true); + const { + data: { settings }, + } = await fetchNotificationSettings(); setSettings(settings?.general?.notifications); - setDisSettings(settings?.discussion?.notifications) - setLoading(false) + setDisSettings(settings?.discussion?.notifications); + setLoading(false); } catch (error) { console.error("An error occurred while loading data:", error); - setLoading(false) + setLoading(false); } }; useEffect(() => { - loadNotificationSettings() - }, []) + loadNotificationSettings(); + }, []); const handleUpdateGen = debounce(async (updatedSettings) => { const payload = { general: { notifications: updatedSettings }, }; - console.log(payload); + try { const response = await updateNotificationSettings(payload); if (response.status === 200) { @@ -115,11 +119,10 @@ function Notifications() { } } catch (error) {} }, 2000); - const handleUpdateDis = debounce(async (updatedSettings) => { const payload = { - discussion: { notifications: updatedSettings } + discussion: { notifications: updatedSettings }, }; try { const response = await updateNotificationSettings(payload); @@ -127,7 +130,7 @@ function Notifications() { setModalOpen(true); dispatch({ type: "UPDATE_NOTIFICATION_SETTINGS", - payload: response?.data + payload: response?.data, }); } } catch (error) {} @@ -159,7 +162,7 @@ function Notifications() { handleUpdateDis(updatedSettings); return updatedSettings; }); - }; + }; const handleModal = () => { setModalOpen(!modalOpen); @@ -182,28 +185,34 @@ function Notifications() { In-app
- {generalInputFields.map((field) => ( -
- {field.label} -
- - handleChange({...field, action, type: field.email})} /> + {generalInputFields.map((field) => ( +
+ {field.label} +
+ + + handleChange({ ...field, action, type: field.email }) + } + /> - handleChange({...field, action, type: field.push})} /> + + handleChange({ ...field, action, type: field.push }) + } + /> +
-
- ))} -
+ ))} +
In-app
- {discussionInputFields.map((field) => ( -
- {field.label} -
- - handleChangeDis({...field, action, type: field.email})} /> + {discussionInputFields.map((field) => ( +
+ {field.label} +
+ + + handleChangeDis({ ...field, action, type: field.email }) + } + /> - handleChangeDis({...field, action, type: field.push})} /> + + handleChangeDis({ ...field, action, type: field.push }) + } + /> +
-
- ))} -
+ ))} +
diff --git a/frontend/mms-Admin/components/settings/Password.js b/frontend/mms-Admin/components/settings/Password.js index 39f97ce1..6d693da5 100644 --- a/frontend/mms-Admin/components/settings/Password.js +++ b/frontend/mms-Admin/components/settings/Password.js @@ -39,17 +39,13 @@ function Password() { newPassword: data.newPassword, oldPassword: data.oldPassword, }); - console.log(response) if (response.status === 200) { - setLoading(false); - setData({}) + setData({}); setIsSuccess(true); - } if (response.status === 400 || response.status === 401) { - setMessage(response.data.message); } } catch (e) { @@ -127,8 +123,6 @@ function Password() { - - {isSuccess && ( { if (JSON.parse(localStorage.getItem("token"))) { @@ -63,7 +63,6 @@ function Support() { try { if (file) { - console.log("here"); formData.append("imageUrl", file); } if (email) { @@ -84,12 +83,12 @@ function Support() { if (response.status === 401 || response.status === 400) { setLoading(false); - setMessage('Could not send Request') + setMessage("Could not send Request"); throw response; } } catch (e) { - setMessage('Could not send Request') + setMessage("Could not send Request"); setLoading(false); } @@ -130,7 +129,7 @@ function Support() { placeholder="body" required /> -