refactor: optimze modal
This commit is contained in:
@@ -14,6 +14,7 @@ export default function MuiModal({
|
||||
submitOnClick,
|
||||
disabled,
|
||||
handleCloseCustom,
|
||||
aboveSubmit,
|
||||
children,
|
||||
}: MuiModalProps) {
|
||||
const [open, setOpen] = useState(false);
|
||||
@@ -57,6 +58,10 @@ export default function MuiModal({
|
||||
<motion.div className="w-full flex-1 flex flex-col justify-between text-center items-center overflow-y-auto">
|
||||
{children}
|
||||
</motion.div>
|
||||
<motion.div className="w-full h-full flex flex-col gap-2">
|
||||
{aboveSubmit && (
|
||||
<div className="w-full flex justify-center">{aboveSubmit}</div>
|
||||
)}
|
||||
<motion.div
|
||||
className={`w-full h-full flex ${
|
||||
submitText ? "justify-end" : "justify-center"
|
||||
@@ -75,6 +80,7 @@ export default function MuiModal({
|
||||
)}
|
||||
</motion.div>
|
||||
</motion.div>
|
||||
</motion.div>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -195,13 +195,13 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
||||
};
|
||||
|
||||
const submitHandler = () => {
|
||||
if (requiresAdvancedVerification) {
|
||||
goToAdvancedVerification();
|
||||
if (hasExtraDescription && !hasReadDescription) {
|
||||
toast.error("لطفا ابتدا توضیحات سرویس را مطالعه و تایید کنید");
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasExtraDescription && !hasReadDescription) {
|
||||
toast.error("لطفا ابتدا توضیحات سرویس را مطالعه و تایید کنید");
|
||||
if (requiresAdvancedVerification) {
|
||||
goToAdvancedVerification();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -213,6 +213,7 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
||||
const payload = {
|
||||
...formik.values,
|
||||
status: "buy",
|
||||
...(hasExtraDescription ? { hasReadDescription: true } : {}),
|
||||
...(needsShahkarVerification ? { nationalCode: nationalCode.trim() } : {}),
|
||||
};
|
||||
|
||||
@@ -291,11 +292,7 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
||||
setIsOpenModal={setIsOpen}
|
||||
submitText={data?.data?.result?.max_config === 0 ? undefined : "خرید"}
|
||||
submitOnClick={submitHandler}
|
||||
disabled={
|
||||
isLoading ||
|
||||
isFetching ||
|
||||
(hasExtraDescription && !hasReadDescription)
|
||||
}
|
||||
disabled={isLoading || isFetching}
|
||||
nameService={
|
||||
isLoading || isFetching
|
||||
? "درحال بارگذاری..."
|
||||
@@ -303,6 +300,19 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
||||
? data?.data.result.title
|
||||
: "خطا رخ داد"
|
||||
}
|
||||
aboveSubmit={
|
||||
hasExtraDescription ? (
|
||||
<label className="w-full flex flex-row-reverse items-center justify-center gap-2 text-xs md:text-sm text-gray-300 cursor-pointer select-none">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={hasReadDescription}
|
||||
onChange={(e) => setHasReadDescription(e.target.checked)}
|
||||
className="w-4 h-4 accent-secondTheme"
|
||||
/>
|
||||
توضیحات سرویس را مطالعه کردم
|
||||
</label>
|
||||
) : undefined
|
||||
}
|
||||
>
|
||||
<div className="relative w-full h-full px-2 md:px-4">
|
||||
{error && (
|
||||
@@ -349,17 +359,6 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
||||
توضیحات سرویس
|
||||
</Button>
|
||||
)}
|
||||
{hasExtraDescription && (
|
||||
<label className="w-full flex flex-row-reverse items-center gap-2 text-xs md:text-sm text-gray-300 cursor-pointer select-none">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={hasReadDescription}
|
||||
onChange={(e) => setHasReadDescription(e.target.checked)}
|
||||
className="w-4 h-4 accent-secondTheme"
|
||||
/>
|
||||
توضیحات سرویس را مطالعه کردم
|
||||
</label>
|
||||
)}
|
||||
<Alert type="danger">
|
||||
{" "}
|
||||
کاربر گرامی لطفا از خاموش بودن vpn خود اطمینان حاصل فرمایید تا در
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Dispatch, SetStateAction } from "react";
|
||||
import MuiModal from "../../../../../common/modal";
|
||||
|
||||
interface DescriptionSection {
|
||||
export interface DescriptionSection {
|
||||
emoji?: string;
|
||||
title?: string;
|
||||
items?: string[];
|
||||
@@ -41,7 +41,6 @@ const ModalDnsServiceInfo = ({
|
||||
isOpenModal={isOpen}
|
||||
setIsOpenModal={setIsOpen}
|
||||
title="توضیحات سرویس"
|
||||
nameService="توضیحات سرویس"
|
||||
>
|
||||
<div className="w-full h-full flex flex-col gap-3 max-sm:text-xs max-md:text-sm text-base">
|
||||
{(sections ?? []).map((section, sectionIndex) => (
|
||||
|
||||
1
src/types/props.d.ts
vendored
1
src/types/props.d.ts
vendored
@@ -116,6 +116,7 @@ export interface MuiModalProps {
|
||||
submitOnClick?: () => void;
|
||||
disabled?: boolean;
|
||||
handleCloseCustom ?: () => void;
|
||||
aboveSubmit?: React.ReactNode;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user