diff --git a/src/components/YourPage/LoadedPage.jsx b/src/components/YourPage/LoadedPage.jsx index 856bc38..5c05431 100644 --- a/src/components/YourPage/LoadedPage.jsx +++ b/src/components/YourPage/LoadedPage.jsx @@ -2,9 +2,8 @@ import React from "react"; import GetMyPageLoad from "./getMyPageLoad"; -const LoadedPage = () => { - const { loading, data, error } = GetMyPageLoad(); - +const LoadedPage = ({reloader}) => { + const { loading, data, error } = GetMyPageLoad(reloader); return (
diff --git a/src/components/YourPage/UpdateButton.jsx b/src/components/YourPage/UpdateButton.jsx index 52ee39b..8ca1448 100644 --- a/src/components/YourPage/UpdateButton.jsx +++ b/src/components/YourPage/UpdateButton.jsx @@ -1,13 +1,19 @@ import LoadingSpinner from "../Spinners/LoadingSpinner"; -const UpdateButton = ({ onClick, loading }) => ( +const UpdateButton = ({ onClick, loading, msg }) => ( ); diff --git a/src/components/YourPage/YourPageForm.jsx b/src/components/YourPage/YourPageForm.jsx index 5dea482..fd570bb 100644 --- a/src/components/YourPage/YourPageForm.jsx +++ b/src/components/YourPage/YourPageForm.jsx @@ -1,7 +1,7 @@ import InputCom from "../Helpers/Inputs/InputCom/index"; import UpdateButton from "./UpdateButton"; -const YourPageForm = ({ values, onChange, onSubmit, loading }) => ( +const YourPageForm = ({ values, onChange, onSubmit, loading, msg }) => (
( />
- +

diff --git a/src/components/YourPage/getMyPageLoad.js b/src/components/YourPage/getMyPageLoad.js index d34339d..58e4696 100644 --- a/src/components/YourPage/getMyPageLoad.js +++ b/src/components/YourPage/getMyPageLoad.js @@ -1,10 +1,9 @@ import { useEffect, useState } from "react"; import usersService from "../../services/UsersService"; -import { useSelector } from "react-redux"; -const GetMyPageLoad = () => { - const { yourPageTable } = useSelector((state) => state.tableReload); +const GetMyPageLoad = (reloader) => { + const api = new usersService(); const [response, setResponse] = useState({ loading: true, @@ -14,20 +13,17 @@ const GetMyPageLoad = () => { useEffect(() => { const fetchData = async () => { - let api = new usersService(); try { const res = await api.MyPageLoad(); setResponse({ loading: false, data: res.data, error: null }); - - console.log(response.data) } catch (error) { setResponse({ loading: false, data: null, error: error.message }); } }; fetchData(); - }, [yourPageTable]); + }, [reloader]); return response; }; diff --git a/src/components/YourPage/index.jsx b/src/components/YourPage/index.jsx index 62e3d24..42faf64 100644 --- a/src/components/YourPage/index.jsx +++ b/src/components/YourPage/index.jsx @@ -1,60 +1,24 @@ import React, { useState } from "react"; -import Layout from "../Partials/Layout"; import usersService from "../../services/UsersService"; -import YourPageForm from "./YourPageForm"; +import Layout from "../Partials/Layout"; import LoadedPage from "./LoadedPage"; -import { useDispatch } from "react-redux"; -import { tableReload } from "../../store/TableReloads"; +import YourPageForm from "./YourPageForm"; +// import { updateYourPage } from "./updateYourPage"; const YourPage = () => { - const dispatch = useDispatch; - const [pageValues, setPageValues] = useState({ - intro: "", - description: "", - }); + const [pageValues, setPageValues] = useState(pageInitialValues); + const [response, setResponse] = useState(responseInitialValues); + const [reloader, setReloader] = useState(false); - const [response, setResponse] = useState({ - loading: false, - data: {}, - error: "", - msg: "", - }); - - const handleChange = (event) => { - let { name, value } = event.target; + const handleChange = ({ target: { name, value } }) => setPageValues((prev) => ({ ...prev, [name]: value })); - }; - const updateYourPageDetails = async () => { - if (!pageValues.intro || !pageValues.description) return; - - try { - setResponse({ loading: true, error: "", msg: "" }); - - let api = new usersService(); - const res = await api.MyPageIntro(pageValues); - - setTimeout(() => { - setResponse({ - loading: false, - data: res.data, - msg: "Page updated successfully", - }); - - dispatch(tableReload({ type: "YourPageTable" })); - - // Clear form after successful update - setPageValues({ intro: "", description: "" }); - }, 2000); - } catch (error) { - setResponse({ - loading: false, - data: {}, - error: "Error updating page", - msg: "", - }); - } - }; + const updateYourPageDetails = updateYourPage( + pageValues, + setResponse, + setPageValues, + setReloader + ); return ( @@ -70,8 +34,9 @@ const YourPage = () => { onChange={handleChange} onSubmit={updateYourPageDetails} loading={response.loading} + msg={response.msg} /> - +
@@ -80,3 +45,51 @@ const YourPage = () => { }; export default YourPage; + +const pageInitialValues = { + intro: "", + description: "", +}; + +const responseInitialValues = { + loading: false, + data: {}, + error: "", + msg: "", +}; + +function updateYourPage(pageValues, setResponse, setPageValues, setReloader) { + return async () => { + if (!pageValues.intro || !pageValues.description) return; + + try { + setResponse({ loading: true, error: "", msg: "" }); + + let api = new usersService(); + const res = await api.MyPageIntro(pageValues); + + setTimeout(() => { + setResponse({ + loading: false, + data: res.data, + msg: "Update Complete", + }); + + setReloader((prev) => !prev); + }, 1000); + + setTimeout(() => { + setResponse({ msg: "" }); + // Clear form after successful update + setPageValues({ intro: "", description: "" }); + }, 3000); + } catch (error) { + return setResponse({ + loading: false, + data: {}, + error: "Error updating page", + msg: "", + }); + } + }; +} diff --git a/src/components/jobPopout/EditJobPopout.jsx b/src/components/jobPopout/EditJobPopout.jsx index a10fca3..7d1f670 100644 --- a/src/components/jobPopout/EditJobPopout.jsx +++ b/src/components/jobPopout/EditJobPopout.jsx @@ -208,12 +208,6 @@ const EditJobPopOut = ({ } }; - // Check if the user is using iOS - const isIOS = /MacIntel|MacPPC/.test(navigator.platform) && !window.MSStream; - - // Check if the user is using Windows - const isWindows = /Windows/.test(navigator.userAgent); - return (
diff --git a/src/store/TableReloads.js b/src/store/TableReloads.js index d32cea5..cc1a298 100644 --- a/src/store/TableReloads.js +++ b/src/store/TableReloads.js @@ -8,7 +8,6 @@ const initialState = { couponTable: false, walletTable: false, uploadsTable: false, - yourPageTable: false, }; export const tableReloadSlice = createSlice({ @@ -38,9 +37,6 @@ export const tableReloadSlice = createSlice({ case "UPLOADSTABLE": state.uploadsTable = !state.uploadsTable; return; - case "YourPageTable": - state.yourPageTable = !state.yourPageTable; - return; default: return state; }