Created
September 19, 2023 16:03
-
-
Save Ebrahim-Ramadan/1f3af2cafec0b98bba621db85c970d34 to your computer and use it in GitHub Desktop.
profile/{name}-id/edit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
'use client' | |
import EditProfile from "@/components/pages/profile/edit/edit"; | |
import { useState, useEffect } from "react"; | |
import secureLocalStorage from "react-secure-storage"; | |
import Reload from '@/components/layout/Reload'; | |
import { ProfileInfoFetching} from "@/services/auth"; | |
import Notfound from "@/app/not-found"; | |
export default function Home() { | |
const [ValidatedToEdit, setValidatedToEdit] = useState(false); | |
const [NotFound, setNotFound] = useState(false); | |
const [fetching, setfetching] = useState(false); | |
const matches = window.location.href.match(/(\d+)(?!.*\d)/) | |
const URL_ID = matches ? matches[0] : null; | |
const extractedText = window.location.href.match(/\/profile\/([^/]+)-\d+\/edit/); | |
const URL_Name = extractedText ? extractedText[1] : null; | |
useEffect(() => { | |
async function FetchPublicProfile(realId, URL_Name) { | |
try { | |
setfetching(true) | |
const AccessToken = secureLocalStorage.getItem("access"); | |
const InfoRes = await ProfileInfoFetching(AccessToken) | |
if (realId == InfoRes.id && URL_Name==(InfoRes.first_name+InfoRes.last_name).replace(/[^a-zA-Z0-9]/g, '')) { | |
setValidatedToEdit(true) | |
} | |
setfetching(false) | |
} catch (error) { | |
setfetching(false) | |
} | |
} | |
FetchPublicProfile(URL_ID, URL_Name) | |
const TimeOutNotFound = setTimeout(() => { | |
setNotFound(true); | |
}, 1500); | |
return () => { | |
clearTimeout(TimeOutNotFound); | |
}; | |
}, [URL_ID, ValidatedToEdit]); | |
return ( | |
<main className="w-full flex flex-col items-center justify-center"> | |
{fetching && ( | |
<Reload/> | |
)} | |
{ValidatedToEdit ? ( | |
<EditProfile /> | |
): ( | |
NotFound&& | |
<Notfound/> | |
)} | |
</main> | |
); | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment