Browse Source

bolgs bug fixed

main
sina_sajjadi 2 months ago
parent
commit
bf635113c0
  1. 2
      src/app/blog/Card13.tsx
  2. 51
      src/app/blog/[...slug]/page.tsx
  3. 109
      src/app/forgot-password/page.tsx
  4. 33
      src/app/login/page.tsx
  5. 58
      src/app/signup/page.tsx

2
src/app/blog/Card13.tsx

@ -14,7 +14,7 @@ const Card13: FC<Card13Props> = ({ className = "", post }) => {
return ( return (
<div className={`nc-Card13 relative flex ${className}`} data-nc-id="Card13">
<div className={`nc-Card13 relative flex justify-between ${className}`} data-nc-id="Card13">
<div className="flex flex-col h-full py-2"> <div className="flex flex-col h-full py-2">
<h2 className={`nc-card-title block font-semibold text-base`}> <h2 className={`nc-card-title block font-semibold text-base`}>
<Link href={`blog/${post?.slug}`} className="line-clamp-2" title={post?.title}> <Link href={`blog/${post?.slug}`} className="line-clamp-2" title={post?.title}>

51
src/app/blog/[...slug]/page.tsx

@ -1,4 +1,4 @@
"use client"
"use client";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { DEMO_POSTS } from "@/data/posts"; import { DEMO_POSTS } from "@/data/posts";
@ -25,21 +25,14 @@ const Page = ({
params: { stepIndex: string }; params: { stepIndex: string };
searchParams?: { [key: string]: string | string[] | undefined }; searchParams?: { [key: string]: string | string[] | undefined };
}) => { }) => {
const [ blog , setBlog] = useState()
const [blog, setBlog] = useState();
useEffect(() => { useEffect(() => {
axiosInstance.get(`/api/blogs/${params.slug[0]}/`)
.then((response)=>{
axiosInstance.get(`/api/blogs/${params.slug[0]}/`).then((response) => {
setBlog(response.data); setBlog(response.data);
})
})
});
});
const renderHeader = () => { const renderHeader = () => {
return ( return (
<header className="container rounded-xl"> <header className="container rounded-xl">
<div className="max-w-screen-md mx-auto space-y-5"> <div className="max-w-screen-md mx-auto space-y-5">
@ -94,36 +87,32 @@ const Page = ({
<div <div
id="single-entry-content" id="single-entry-content"
className="prose dark:prose-invert prose-sm !max-w-screen-md sm:prose lg:prose-lg mx-auto dark:prose-dark" className="prose dark:prose-invert prose-sm !max-w-screen-md sm:prose lg:prose-lg mx-auto dark:prose-dark"
><div dangerouslySetInnerHTML={{ __html: blog?.content }} />
>
<div dangerouslySetInnerHTML={{ __html: blog?.content }} />
</div> </div>
); );
}; };
const renderTags = () => { const renderTags = () => {
console.log(blog?.tags[0].name);
return( return(
<div className="max-w-screen-md mx-auto flex flex-wrap">
<a
className="nc-Tag inline-block bg-white text-sm text-neutral-600 dark:text-neutral-300 py-2 rounded-lg border border-neutral-100 md:px-4 dark:bg-neutral-700 dark:border-neutral-700 hover:border-neutral-200 dark:hover:border-neutral-6000 mr-2 mb-2"
href="##"
>
Garden
</a>
<a
className="nc-Tag inline-block bg-white text-sm text-neutral-600 dark:text-neutral-300 py-2 rounded-lg border border-neutral-100 md:px-4 dark:bg-neutral-700 dark:border-neutral-700 hover:border-neutral-200 dark:hover:border-neutral-6000 mr-2 mb-2"
href="##"
>
Jewelry
</a>
(<div className="max-w-screen-md mx-auto flex flex-wrap">
{blog?.tags.map((item) => (
<a <a
className="nc-Tag inline-block bg-white text-sm text-neutral-600 dark:text-neutral-300 py-2 rounded-lg border border-neutral-100 md:px-4 dark:bg-neutral-700 dark:border-neutral-700 hover:border-neutral-200 dark:hover:border-neutral-6000 mr-2 mb-2" className="nc-Tag inline-block bg-white text-sm text-neutral-600 dark:text-neutral-300 py-2 rounded-lg border border-neutral-100 md:px-4 dark:bg-neutral-700 dark:border-neutral-700 hover:border-neutral-200 dark:hover:border-neutral-6000 mr-2 mb-2"
href="##"
href={item.slug}
> >
Tools
{item.name}
</a> </a>
</div>
);
};
))}
</div>)
)
};
const renderCommentForm = () => { const renderCommentForm = () => {
return ( return (

109
src/app/forgot-password/page.tsx

@ -10,6 +10,7 @@ import { useUserContext } from "@/components/contexts/userContext";
import { ToastContainer, toast } from "react-toastify"; import { ToastContainer, toast } from "react-toastify";
import "react-toastify/dist/ReactToastify.css"; import "react-toastify/dist/ReactToastify.css";
import { PhoneNumberUtil, PhoneNumberFormat } from "google-libphonenumber"; // Import libphonenumber import { PhoneNumberUtil, PhoneNumberFormat } from "google-libphonenumber"; // Import libphonenumber
import { BiShow, BiHide } from "react-icons/bi";
export interface PageSignUpProps {} export interface PageSignUpProps {}
@ -18,14 +19,20 @@ const PageSignUp: FC<PageSignUpProps> = () => {
const { setForm, setMethod } = useUserContext(); const { setForm, setMethod } = useUserContext();
const phoneUtil = PhoneNumberUtil.getInstance(); const phoneUtil = PhoneNumberUtil.getInstance();
const [name, setName] = useState('');
const [countryCode, setCountryCode] = useState('968');
const [phoneNumber, setPhoneNumber] = useState('');
const [password, setPassword] = useState('');
const [confirmPassword, setConfirmPassword] = useState('');
const [loading , setLoading] = useState(false)
const [errors, setErrors] = useState<{ phoneNumber?: string; password?: string; confirmPassword?: string; countryCode? : string }>({});
const [name, setName] = useState("");
const [countryCode, setCountryCode] = useState("968");
const [phoneNumber, setPhoneNumber] = useState("");
const [password, setPassword] = useState("");
const [confirmPassword, setConfirmPassword] = useState("");
const [loading, setLoading] = useState(false);
const [showPassword, setShowPassword] = useState(false);
const [showConfirm, setShowConfirm] = useState(false);
const [errors, setErrors] = useState<{
phoneNumber?: string;
password?: string;
confirmPassword?: string;
countryCode?: string;
}>({});
const countryCodeHandler = (e: React.ChangeEvent<HTMLInputElement>) => { const countryCodeHandler = (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.value.length <= 3) { if (e.target.value.length <= 3) {
@ -35,7 +42,10 @@ const PageSignUp: FC<PageSignUpProps> = () => {
const validatePhoneNumber = () => { const validatePhoneNumber = () => {
try { try {
const number = phoneUtil.parseAndKeepRawInput("+" + countryCode + phoneNumber, countryCode);
const number = phoneUtil.parseAndKeepRawInput(
"+" + countryCode + phoneNumber,
countryCode
);
if (!phoneUtil.isValidNumber(number)) { if (!phoneUtil.isValidNumber(number)) {
return "Invalid phone number."; return "Invalid phone number.";
} }
@ -46,12 +56,17 @@ const PageSignUp: FC<PageSignUpProps> = () => {
}; };
const validateForm = () => { const validateForm = () => {
const newErrors: { phoneNumber?: string; password?: string; confirmPassword?: string } = {};
const newErrors: {
phoneNumber?: string;
password?: string;
confirmPassword?: string;
} = {};
const phoneError = validatePhoneNumber(); const phoneError = validatePhoneNumber();
if (phoneError) newErrors.phoneNumber = phoneError; if (phoneError) newErrors.phoneNumber = phoneError;
if (!password) newErrors.password = "Password is required."; if (!password) newErrors.password = "Password is required.";
if (password !== confirmPassword) newErrors.confirmPassword = "Passwords do not match.";
if (password !== confirmPassword)
newErrors.confirmPassword = "Passwords do not match.";
setErrors(newErrors); setErrors(newErrors);
return Object.keys(newErrors).length === 0; // Return true if no errors return Object.keys(newErrors).length === 0; // Return true if no errors
@ -73,7 +88,7 @@ const PageSignUp: FC<PageSignUpProps> = () => {
}, [errors]); }, [errors]);
const submitHandler = async () => { const submitHandler = async () => {
setLoading(true)
setLoading(true);
setErrors({}); // Clear previous errors setErrors({}); // Clear previous errors
if (!validateForm()) { if (!validateForm()) {
@ -109,9 +124,8 @@ const PageSignUp: FC<PageSignUpProps> = () => {
theme: "light", theme: "light",
}); });
} finally { } finally {
setLoading(false)
setLoading(false);
} }
}; };
return ( return (
@ -121,13 +135,24 @@ const PageSignUp: FC<PageSignUpProps> = () => {
Change Password Change Password
</h2> </h2>
<div className="max-w-md mx-auto space-y-6"> <div className="max-w-md mx-auto space-y-6">
<form className="grid grid-cols-1 gap-6" onSubmit={(e) => e.preventDefault()}>
<form
className="grid grid-cols-1 gap-6"
onSubmit={(e) => e.preventDefault()}
>
<label className="block"> <label className="block">
<span className="text-neutral-800 dark:text-neutral-200"> <span className="text-neutral-800 dark:text-neutral-200">
Phone Number Phone Number
</span> </span>
<div className={`flex items-center mt-1 rounded-2xl ${errors.countryCode || errors.phoneNumber ? "border border-red-600" : "border border-neutral-200"} bg-white dark:border-neutral-700 dark:bg-neutral-900 focus-within:border-primary-300 focus-within:ring focus-within:ring-primary-200 focus-within:ring-opacity-50`}>
<span className="px-2 mr-[-15px] text-neutral-800 dark:text-neutral-200">+</span>
<div
className={`flex items-center mt-1 rounded-2xl ${
errors.countryCode || errors.phoneNumber
? "border border-red-600"
: "border border-neutral-200"
} bg-white dark:border-neutral-700 dark:bg-neutral-900 focus-within:border-primary-300 focus-within:ring focus-within:ring-primary-200 focus-within:ring-opacity-50`}
>
<span className="px-2 mr-[-15px] text-neutral-800 dark:text-neutral-200">
+
</span>
<input <input
value={countryCode} value={countryCode}
onChange={countryCodeHandler} onChange={countryCodeHandler}
@ -145,25 +170,59 @@ const PageSignUp: FC<PageSignUpProps> = () => {
/> />
</div> </div>
</label> </label>
<label className="block">
<span className="flex justify-between items-center text-neutral-800 dark:text-neutral-200">Password</span>
<label className="block relative">
<span className="flex justify-between items-center text-neutral-800 dark:text-neutral-200">
Password
</span>
<Input <Input
value={password} value={password}
onChange={(e) => setPassword(e.target.value)} onChange={(e) => setPassword(e.target.value)}
type="password"
type={`${showPassword ? "text" : "password"}`}
className={`mt-1 ${errors.password ? "border-red-600" : ""}`} className={`mt-1 ${errors.password ? "border-red-600" : ""}`}
/> />
{showPassword ? (
<BiShow
size={20}
className="box-content rounded-full hover:bg-slate-100 p-[5px] absolute top-9 right-4"
onClick={(e) => setShowPassword((prev) => !prev)}
/>
) : (
<BiHide
size={20}
className="box-content rounded-full hover:bg-slate-100 p-[5px] absolute top-9 right-4"
onClick={(e) => setShowPassword((prev) => !prev)}
/>
)}
</label> </label>
<label className="block">
<span className="flex justify-between items-center text-neutral-800 dark:text-neutral-200">Confirm Password</span>
<label className="block relative">
<span className="flex justify-between items-center text-neutral-800 dark:text-neutral-200">
Confirm Password
</span>
<Input <Input
value={confirmPassword} value={confirmPassword}
onChange={(e) => setConfirmPassword(e.target.value)} onChange={(e) => setConfirmPassword(e.target.value)}
type="password"
className={`mt-1 ${errors.confirmPassword ? "border-red-600" : ""}`}
type={`${showConfirm ? "text" : "password"}`}
className={`mt-1 ${
errors.confirmPassword ? "border-red-600" : ""
}`}
/>
{showConfirm ? (
<BiShow
size={20}
className="box-content rounded-full hover:bg-slate-100 p-[5px] absolute top-9 right-4"
onClick={(e) => setShowConfirm((prev) => !prev)}
/>
) : (
<BiHide
size={20}
className="box-content rounded-full hover:bg-slate-100 p-[5px] absolute top-9 right-4"
onClick={(e) => setShowConfirm((prev) => !prev)}
/> />
)}
</label> </label>
<ButtonPrimary loading={loading} onClick={submitHandler}>Continue</ButtonPrimary>
<ButtonPrimary loading={loading} onClick={submitHandler}>
Continue
</ButtonPrimary>
</form> </form>
</div> </div>
</div> </div>

33
src/app/login/page.tsx

@ -9,7 +9,8 @@ import { useRouter } from "next/navigation";
import { useUserContext } from "@/components/contexts/userContext"; import { useUserContext } from "@/components/contexts/userContext";
import { ToastContainer, toast } from "react-toastify"; import { ToastContainer, toast } from "react-toastify";
import "react-toastify/dist/ReactToastify.css"; import "react-toastify/dist/ReactToastify.css";
import { PhoneNumberUtil } from 'google-libphonenumber';
import { PhoneNumberUtil } from "google-libphonenumber";
import { BiShow, BiHide } from "react-icons/bi";
export interface PageLoginProps {} export interface PageLoginProps {}
@ -23,6 +24,7 @@ const PageLogin: FC<PageLoginProps> = () => {
const [countryCode, setCountryCode] = useState<string>("968"); const [countryCode, setCountryCode] = useState<string>("968");
const [loading, setLoading] = useState<boolean>(false); const [loading, setLoading] = useState<boolean>(false);
const [errors, setErrors] = useState<{ phoneNumber?: string; password?: string }>({}); const [errors, setErrors] = useState<{ phoneNumber?: string; password?: string }>({});
const [showPassword, setShowPassword] = useState(false); // New state for show/hide password
// Redirect to home if the user is already logged in // Redirect to home if the user is already logged in
useEffect(() => { useEffect(() => {
@ -149,12 +151,12 @@ const PageLogin: FC<PageLoginProps> = () => {
<div className="max-w-md mx-auto space-y-6"> <div className="max-w-md mx-auto space-y-6">
<form className="grid grid-cols-1 gap-6" onSubmit={(e) => e.preventDefault()}> <form className="grid grid-cols-1 gap-6" onSubmit={(e) => e.preventDefault()}>
<label className="block"> <label className="block">
<span className="text-neutral-800 dark:text-neutral-200">
Phone Number
</span>
<div className={`flex items-center mt-1 rounded-2xl ${
<span className="text-neutral-800 dark:text-neutral-200">Phone Number</span>
<div
className={`flex items-center mt-1 rounded-2xl ${
errors.phoneNumber ? "border border-red-600" : "border border-neutral-200" errors.phoneNumber ? "border border-red-600" : "border border-neutral-200"
} bg-white dark:border-neutral-700 dark:bg-neutral-900 focus-within:border-primary-300 focus-within:ring focus-within:ring-primary-200 focus-within:ring-opacity-50`}>
} bg-white dark:border-neutral-700 dark:bg-neutral-900 focus-within:border-primary-300 focus-within:ring focus-within:ring-primary-200 focus-within:ring-opacity-50`}
>
<span className="px-2 mr-[-15px] text-neutral-800 dark:text-neutral-200">+</span> <span className="px-2 mr-[-15px] text-neutral-800 dark:text-neutral-200">+</span>
<input <input
value={countryCode} value={countryCode}
@ -174,7 +176,7 @@ const PageLogin: FC<PageLoginProps> = () => {
</div> </div>
</label> </label>
<label className="block">
<label className="block relative">
<span className="flex justify-between items-center text-neutral-800 dark:text-neutral-200"> <span className="flex justify-between items-center text-neutral-800 dark:text-neutral-200">
Password Password
<Link href="/forgot-password" className="text-sm underline font-medium"> <Link href="/forgot-password" className="text-sm underline font-medium">
@ -184,9 +186,22 @@ const PageLogin: FC<PageLoginProps> = () => {
<Input <Input
value={password} value={password}
onChange={(e) => setPassword(e.target.value)} onChange={(e) => setPassword(e.target.value)}
type="password"
className={`secure-input mt-1 ${errors.password ? "border-red-600" : "border-neutral-300"}`}
type={`${showPassword ? "text" : "password"}`}
className={`mt-1 ${errors.password ? "border-red-600" : "border-neutral-300"}`}
/>
{showPassword ? (
<BiShow
size={20}
className="box-content rounded-full hover:bg-slate-100 p-[5px] absolute top-9 right-4"
onClick={() => setShowPassword((prev) => !prev)}
/>
) : (
<BiHide
size={20}
className="box-content rounded-full hover:bg-slate-100 p-[5px] absolute top-9 right-4"
onClick={() => setShowPassword((prev) => !prev)}
/> />
)}
</label> </label>
<ButtonPrimary onClick={submitHandler} loading={loading}> <ButtonPrimary onClick={submitHandler} loading={loading}>

58
src/app/signup/page.tsx

@ -10,6 +10,7 @@ import useFormValidation from "@/hooks/FormValidation";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import { ToastContainer, toast } from "react-toastify"; import { ToastContainer, toast } from "react-toastify";
import "react-toastify/dist/ReactToastify.css"; import "react-toastify/dist/ReactToastify.css";
import { BiShow, BiHide } from "react-icons/bi";
export interface PageSignUpProps {} export interface PageSignUpProps {}
@ -25,6 +26,8 @@ const PageSignUp: FC<PageSignUpProps> = () => {
const [failed, setFailed] = useState<string>(""); const [failed, setFailed] = useState<string>("");
const { errors, validateForm } = useFormValidation(); const { errors, validateForm } = useFormValidation();
const [showPassword, setShowPassword] = useState(false);
const [showConfirmPassword, setShowConfirmPassword] = useState(false);
const countryCodeHandler = (e: React.ChangeEvent<HTMLInputElement>) => { const countryCodeHandler = (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.value.length <= 3) { if (e.target.value.length <= 3) {
@ -89,10 +92,7 @@ const PageSignUp: FC<PageSignUpProps> = () => {
Signup Signup
</h2> </h2>
<div className="max-w-md mx-auto space-y-6"> <div className="max-w-md mx-auto space-y-6">
<form
className="grid grid-cols-1 gap-6"
onSubmit={(e) => e.preventDefault()}
>
<form className="grid grid-cols-1 gap-6" onSubmit={(e) => e.preventDefault()}>
<label className="block"> <label className="block">
<span className="text-neutral-800 dark:text-neutral-200">Full Name</span> <span className="text-neutral-800 dark:text-neutral-200">Full Name</span>
<Input <Input
@ -105,9 +105,11 @@ const PageSignUp: FC<PageSignUpProps> = () => {
</label> </label>
<label className="block"> <label className="block">
<span className="text-neutral-800 dark:text-neutral-200">Phone Number</span> <span className="text-neutral-800 dark:text-neutral-200">Phone Number</span>
<div className={`flex items-center mt-1 rounded-2xl ${
<div
className={`flex items-center mt-1 rounded-2xl ${
errors.countryCode || errors.phoneNumber ? "border border-red-600" : "border border-neutral-200" errors.countryCode || errors.phoneNumber ? "border border-red-600" : "border border-neutral-200"
} bg-white dark:border-neutral-700 dark:bg-neutral-900 focus-within:border-primary-300 focus-within:ring focus-within:ring-primary-200 focus-within:ring-opacity-50`}>
} bg-white dark:border-neutral-700 dark:bg-neutral-900 focus-within:border-primary-300 focus-within:ring focus-within:ring-primary-200 focus-within:ring-opacity-50`}
>
<span className="px-2 mr-[-15px] text-neutral-800 dark:text-neutral-200">+</span> <span className="px-2 mr-[-15px] text-neutral-800 dark:text-neutral-200">+</span>
<input <input
value={countryCode} value={countryCode}
@ -126,30 +128,52 @@ const PageSignUp: FC<PageSignUpProps> = () => {
/> />
</div> </div>
</label> </label>
<label className="block">
<label className="block relative">
<span className="flex justify-between items-center text-neutral-800 dark:text-neutral-200">Password</span> <span className="flex justify-between items-center text-neutral-800 dark:text-neutral-200">Password</span>
<Input <Input
value={password} value={password}
onChange={(e) => setPassword(e.target.value)} onChange={(e) => setPassword(e.target.value)}
type="password"
className={`secure-input mt-1 ${errors.password ? "border-red-600" : "border-neutral-300"}`}
type={showPassword ? "text" : "password"}
className={`mt-1 ${errors.password ? "border-red-600" : "border-neutral-300"}`}
/>
{showPassword ? (
<BiShow
size={20}
className="box-content rounded-full hover:bg-slate-100 p-[5px] absolute top-9 right-4"
onClick={() => setShowPassword((prev) => !prev)}
/>
) : (
<BiHide
size={20}
className="box-content rounded-full hover:bg-slate-100 p-[5px] absolute top-9 right-4"
onClick={() => setShowPassword((prev) => !prev)}
/> />
)}
</label> </label>
<label className="block">
<label className="block relative">
<span className="flex justify-between items-center text-neutral-800 dark:text-neutral-200">Confirm Password</span> <span className="flex justify-between items-center text-neutral-800 dark:text-neutral-200">Confirm Password</span>
<Input <Input
value={confirmPassword} value={confirmPassword}
onChange={(e) => setConfirmPassword(e.target.value)} onChange={(e) => setConfirmPassword(e.target.value)}
type="password"
className={`secure-input mt-1 ${errors.confirmPassword ? "border-red-600" : "border-neutral-300"}`}
type={showConfirmPassword ? "text" : "password"}
className={` mt-1 ${errors.confirmPassword ? "border-red-600" : "border-neutral-300"}`}
/>
{showConfirmPassword ? (
<BiShow
size={20}
className="box-content rounded-full hover:bg-slate-100 p-[5px] absolute top-9 right-4"
onClick={() => setShowConfirmPassword((prev) => !prev)}
/> />
) : (
<BiHide
size={20}
className="box-content rounded-full hover:bg-slate-100 p-[5px] absolute top-9 right-4"
onClick={() => setShowConfirmPassword((prev) => !prev)}
/>
)}
</label> </label>
{failed && <p className="text-xs text-red-600">{failed}</p>} {failed && <p className="text-xs text-red-600">{failed}</p>}
<ButtonPrimary
loading={loading}
onClick={submitHandler}
disabled={loading}
>
<ButtonPrimary loading={loading} onClick={submitHandler} disabled={loading}>
Continue Continue
</ButtonPrimary> </ButtonPrimary>
</form> </form>

Loading…
Cancel
Save