diff --git a/app/component/ProfressDetail.js b/app/component/ProfressDetail.js index 1a0d028..3df210b 100644 --- a/app/component/ProfressDetail.js +++ b/app/component/ProfressDetail.js @@ -8,7 +8,7 @@ function ProgressDetail({ data }) { {data.label}

- {numberToArStyle(data.progress)}% + {numberToArStyle(data)}%

); diff --git a/app/component/comment/ItemUser.js b/app/component/comment/ItemUser.js index 10617c4..6e5dd3b 100644 --- a/app/component/comment/ItemUser.js +++ b/app/component/comment/ItemUser.js @@ -9,7 +9,7 @@ import LikeComment from "@/components/icons/LikeComment"; import Replies from "./Replies"; import AnswerField from "./AnswerField"; import SendAnswer from "./SendAnswer"; -import { timeAgo } from "@/helper"; +import { alert, isUserLoggedIn, timeAgo } from "@/helper"; import { request } from "@/services/response"; import { useState } from "react"; @@ -142,8 +142,15 @@ function ItemUser({ update, setUpdate, data }) { + ); +} + +export default BtnNewComment; diff --git a/components/doctor/detailDoctor/cards/comments/modal/ModalAnswer.js b/components/doctor/detailDoctor/cards/comments/modal/ModalAnswer.js index 649d81a..2d04b36 100644 --- a/components/doctor/detailDoctor/cards/comments/modal/ModalAnswer.js +++ b/components/doctor/detailDoctor/cards/comments/modal/ModalAnswer.js @@ -2,14 +2,14 @@ import { useState } from "react"; import { styleDefault } from "@/mui"; -import { Box, Button, Modal, Rating, Slider } from "@mui/material"; +import { Box, Button, Modal, Rating } from "@mui/material"; import CloseModalD from "@/components/icons/CloseModalD"; import Field from "@/app/component/fields/Field"; import ArrowLeftD from "@/components/icons/ArrowLeftD"; import ProgressChange from "@/app/component/ProgressChange"; import ProgressDetail from "@/data/progress_detail.json"; -import Link from "next/link"; import { request } from "@/services/response"; +import BtnNewComment from "./BtnNewComment"; function ModalAnswer({ doctor }) { const [open, setOpen] = useState(false); @@ -81,14 +81,7 @@ function ModalAnswer({ doctor }) { return ( <> - +
- +
); diff --git a/components/doctors/head/index.js b/components/doctors/head/index.js index ce0a8ca..33822a3 100644 --- a/components/doctors/head/index.js +++ b/components/doctors/head/index.js @@ -27,16 +27,22 @@ function Head({ matchedCity, matchedState, setDoctors }) { searchParams.get("city") || (matchedCity?.name && matchedCity?.id !== "63" ? matchedCity?.name : false); + const valCategory = isParent + ? findItem("id", isParent) + : findItem("name", fieldName); + const valSpecialty = isParent && findItem("name", fieldName); + const defaultFilter = { state: selectedState && states.find((item) => item.name === selectedState), city: selectedCity && cities.find((item) => item.name === selectedCity), - category: isParent ? findItem("id", isParent) : findItem("name", fieldName), - specialty: isParent && findItem("name", fieldName), + category: valCategory, + specialty: valSpecialty, active: searchParams.get("active") || 0, gender: searchParams.get("gender") || "هر دو", degree: searchParams.get("degree") || "همه موارد", sort: (searchParams.get("sort") && Number(searchParams.get("sort"))) || "", - name: searchParams.get("name") || "", + name: + searchParams.get("name") || valSpecialty?.name || valCategory?.name || "", }; const [filter, setFilter] = useState(defaultFilter); @@ -55,11 +61,12 @@ function Head({ matchedCity, matchedState, setDoctors }) { isReq && sendReq(newFilter); }; const sendReq = (newFilter) => { - const params = QueryForDoctorsReq(newFilter || filter); + const data = newFilter || filter; + const params = QueryForDoctorsReq(data); let filteredName = params; if ( - newFilter.name === newFilter.specialty?.name || - newFilter.name === newFilter.category?.name + data?.name === data.specialty?.name || + data?.name === data.category?.name ) { filteredName.name = ""; delete filteredName.name; diff --git a/components/doctors/search/AutoComplete.js b/components/doctors/search/AutoComplete.js index aa44af6..4127521 100644 --- a/components/doctors/search/AutoComplete.js +++ b/components/doctors/search/AutoComplete.js @@ -1,42 +1,76 @@ import { Autocomplete, TextField } from "@mui/material"; +import { useRef, useState, useEffect } from "react"; function AutoComplete({ data, noneBg, clearText, - inputValue, + inputValue, // مقدار کنترل‌شده از والد (اختیاری) placeholder, - handleSearch, - setInputValue, + handleSearch, // تابعی که باید با مقدار جستجو صدا زده بشه + setInputValue, // اختیاری: اگه والد دوست داره همون‌وقت مقدار رو بگیره setSelectedOption, + debounce = 500, // قابل تنظیم }) { - const clearIndicatorProps = clearText - ? { - clearIndicator: { - onClick: () => { - clearText(); - }, - }, - } - : {}; + const typingTimeoutRef = useRef(null); + const [localInput, setLocalInput] = useState(inputValue || ""); + + // همگام‌سازی وقتی والد مقدار کنترل‌شده رو تغییر میده (مثلاً بعد از انتخاب گزینه) + useEffect(() => { + setLocalInput(inputValue || ""); + }, [inputValue]); + + // پاک‌کردن تایمر هنگام unmount + useEffect(() => { + return () => { + if (typingTimeoutRef.current) clearTimeout(typingTimeoutRef.current); + }; + }, []); + + const onInputChange = (_, newInputValue) => { + // نمایش آنی تایپ کاربر + setLocalInput(newInputValue); + + // اختیاری: اگر والد خواست همون‌جا مقدار رو بگیره + if (setInputValue) setInputValue(newInputValue); + + // پاک کردن تایمر قبلی و ست کردن تایمر جدید برای debounce + if (typingTimeoutRef.current) clearTimeout(typingTimeoutRef.current); + typingTimeoutRef.current = setTimeout(() => { + handleSearch(newInputValue); + }, debounce); + }; + + const onChange = (_, newValue) => { + // انتخاب از لیست — مقدار رو فوراً پردازش کن + if (typingTimeoutRef.current) { + clearTimeout(typingTimeoutRef.current); + typingTimeoutRef.current = null; + } + + const val = newValue + ? typeof newValue === "string" + ? newValue + : newValue.name + : ""; + setLocalInput(val); + setSelectedOption && setSelectedOption(newValue); + handleSearch(val); // اجرای فوری روی انتخاب + if (setInputValue) setInputValue(val); + }; return ( option.name} + getOptionLabel={(option) => + typeof option === "string" ? option : option.name + } disableClearable - inputValue={inputValue || ""} + inputValue={localInput} // ← نمایش آنی از local state className="!w-full" - onInputChange={(_, newInputValue) => { - setInputValue && setInputValue(newInputValue); - handleSearch(newInputValue); - }} - onChange={(_, newValue) => { - setSelectedOption && setSelectedOption(newValue); - handleSearch(newValue ? newValue.name : ""); - }} - // componentsProps={clearIndicatorProps} + onInputChange={onInputChange} + onChange={onChange} renderOption={(props, option) => (
  • {option.name} diff --git a/components/panel/addDoctor/form/sendReq/index.js b/components/panel/addDoctor/form/sendReq/index.js index 05cefc7..ba185dc 100644 --- a/components/panel/addDoctor/form/sendReq/index.js +++ b/components/panel/addDoctor/form/sendReq/index.js @@ -2,9 +2,8 @@ import ArrowLeftPA from "@/components/icons/ArrowLeftPA"; import { alert, checkAllValues } from "@/helper"; import { request } from "@/services/response"; import { Button } from "@mui/material"; -import { useEffect, useState } from "react"; +import { useState } from "react"; import { transformData } from "./function"; -import { toast, ToastContainer } from "react-toastify"; function SendReq({ img, data, resetData }) { const [loading, setLoading] = useState(false); diff --git a/helper/index.js b/helper/index.js index dd101fd..f398a9a 100644 --- a/helper/index.js +++ b/helper/index.js @@ -460,3 +460,8 @@ export function timeAgo(timestamp) { return `${years} سال پیش`; } } + +export function isUserLoggedIn() { + const userInfo = Cookies.get("userInfo"); + return !!userInfo; +}