From b5266d7392011cd8d8b31827f7e7cf938248149a Mon Sep 17 00:00:00 2001 From: John Doe Date: Tue, 12 Sep 2023 19:45:32 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=9F=20Added=20photo=20URLs=20to=20PHOT?= =?UTF-8?q?OS=20array=20=F0=9F=9B=A0=20Updated=20Amenities=5Fdemos=20with?= =?UTF-8?q?=20icons=20=F0=9F=93=B7=20Initialized=20imageGallery=20with=20p?= =?UTF-8?q?hoto=20data=20=F0=9F=9A=80=20Implemented=20image=20loading=20fu?= =?UTF-8?q?nctionality=20=F0=9F=8E=A8=20Improved=20code=20readability=20an?= =?UTF-8?q?d=20structure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listing-stay-detail/GuestsInput.tsx | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 src/app/(listing-detail)/listing-stay-detail/GuestsInput.tsx diff --git a/src/app/(listing-detail)/listing-stay-detail/GuestsInput.tsx b/src/app/(listing-detail)/listing-stay-detail/GuestsInput.tsx new file mode 100644 index 0000000..df55385 --- /dev/null +++ b/src/app/(listing-detail)/listing-stay-detail/GuestsInput.tsx @@ -0,0 +1,122 @@ +"use client"; + +import React, { Fragment, FC, useState } from "react"; +import { Popover, Transition } from "@headlessui/react"; +import NcInputNumber from "@/components/NcInputNumber"; +import { UserPlusIcon } from "@heroicons/react/24/outline"; +import ClearDataButton from "@/app/(client-components)/(HeroSearchForm)/ClearDataButton"; +import { GuestsObject } from "@/app/(client-components)/type"; + +export interface GuestsInputProps { + className?: string; +} + +const GuestsInput: FC = ({ className = "flex-1" }) => { + const [guestAdultsInputValue, setGuestAdultsInputValue] = useState(2); + const [guestChildrenInputValue, setGuestChildrenInputValue] = useState(1); + const [guestInfantsInputValue, setGuestInfantsInputValue] = useState(1); + + const handleChangeData = (value: number, type: keyof GuestsObject) => { + let newValue = { + guestAdults: guestAdultsInputValue, + guestChildren: guestChildrenInputValue, + guestInfants: guestInfantsInputValue, + }; + if (type === "guestAdults") { + setGuestAdultsInputValue(value); + newValue.guestAdults = value; + } + if (type === "guestChildren") { + setGuestChildrenInputValue(value); + newValue.guestChildren = value; + } + if (type === "guestInfants") { + setGuestInfantsInputValue(value); + newValue.guestInfants = value; + } + }; + + const totalGuests = + guestChildrenInputValue + guestAdultsInputValue + guestInfantsInputValue; + + return ( + + {({ open }) => ( + <> +
+ +
+ +
+
+ + {totalGuests || ""} Guests + + + {totalGuests ? "Guests" : "Add guests"} + +
+ + {!!totalGuests && open && ( + { + setGuestAdultsInputValue(0); + setGuestChildrenInputValue(0); + setGuestInfantsInputValue(0); + }} + /> + )} +
+
+ + + + handleChangeData(value, "guestAdults")} + max={10} + min={1} + label="Adults" + desc="Ages 13 or above" + /> + handleChangeData(value, "guestChildren")} + max={4} + label="Children" + desc="Ages 2–12" + /> + + handleChangeData(value, "guestInfants")} + max={4} + label="Infants" + desc="Ages 0–2" + /> + + + + )} +
+ ); +}; + +export default GuestsInput;