From e5dc7912712e5a0c3f1c1a406f1f7aa480c803d4 Mon Sep 17 00:00:00 2001 From: Antoine M Date: Thu, 1 Feb 2024 18:25:01 +0100 Subject: [PATCH] working on select compoonents --- src/assets/img/select_deploy_icon.svg | 10 +++++ src/components/CountrySelect.jsx | 53 ++++++++++++++++++--------- src/components/ProfileSelect.jsx | 35 +++++++++++++++--- 3 files changed, 75 insertions(+), 23 deletions(-) create mode 100644 src/assets/img/select_deploy_icon.svg diff --git a/src/assets/img/select_deploy_icon.svg b/src/assets/img/select_deploy_icon.svg new file mode 100644 index 0000000..49f6a71 --- /dev/null +++ b/src/assets/img/select_deploy_icon.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/components/CountrySelect.jsx b/src/components/CountrySelect.jsx index 71ef76d..b3e8867 100644 --- a/src/components/CountrySelect.jsx +++ b/src/components/CountrySelect.jsx @@ -1,28 +1,45 @@ -import React from "react"; -import { COUNTRIES } from "../utils/countries.js"; +import { useState } from "react"; import { v4 as uuidv4 } from "uuid"; +import { useWordpressCustomData } from "../hooks/WordpressFetchData.js"; +import { useUserContext } from "../hooks/useUserContext.jsx"; export default function CountrySelect() { - const test = COUNTRIES.map((country) => { - if (!country.value) return; - return ( -
  • - - {country.title} -
  • - ); - }); + const availableCountries = useWordpressCustomData("/available-countries"); + const { country, changeCountry } = useUserContext(); - if (!COUNTRIES) return; + const [isSubmenuOpen, setIsSubmenuOpen] = useState(false); + + if (!availableCountries || !country) return
    Loading...
    ; + + function handleChangeCountry(key, value) { + changeCountry({ name: value, iso: key }); + handleShowHideSubmenu(); + } + function handleShowHideSubmenu() { + setIsSubmenuOpen(!isSubmenuOpen); + } + + const countryOptions = Object.keys(availableCountries).map((key, value) => ( +
  • handleChangeCountry(key, availableCountries[key])}> + + {availableCountries[key]} +
  • + )); + + if (!countryOptions) return; return (
    - - ; + +
    ); } diff --git a/src/components/ProfileSelect.jsx b/src/components/ProfileSelect.jsx index a96412b..4fff3d3 100644 --- a/src/components/ProfileSelect.jsx +++ b/src/components/ProfileSelect.jsx @@ -1,10 +1,35 @@ -import React from "react"; +import React, { useState } from "react"; import { v4 as uuidv4 } from "uuid"; +import { useUserContext } from "../hooks/useUserContext"; + +export default function CountrySelect({ options }) { + const [isSubmenuOpen, setIsSubmenuOpen] = useState(false); + const { profile, changeProfile } = useUserContext(); + + function handleShowHideSubmenu() { + setIsSubmenuOpen(!isSubmenuOpen); + } + + function handleChangeProfile() { + changeProfile("subcontractor_employee"); + } + + if (!profile) return
    Loading...
    ; + + const selectOptions = Object.keys(options).map((key) => ( +
  • handleChangeProfile()}> + {options[key]} +
  • + )); -export default function CountrySelect() { return ( - +
    + + +
    ); }