Organization_Management : Organization Hierarchy #443
@ -9,6 +9,7 @@ import Modal from "../common/Modal";
|
|||||||
import { useOrganization } from "../../hooks/useDirectory";
|
import { useOrganization } from "../../hooks/useDirectory";
|
||||||
import { useOrganizationModal } from "../../hooks/useOrganization";
|
import { useOrganizationModal } from "../../hooks/useOrganization";
|
||||||
import Label from "../common/Label";
|
import Label from "../common/Label";
|
||||||
|
import SelectMultiple from "../common/SelectMultiple";
|
||||||
|
|
||||||
const ManageOrganization = () => {
|
const ManageOrganization = () => {
|
||||||
const orgModal = useOrganizationModal();
|
const orgModal = useOrganizationModal();
|
||||||
@ -48,6 +49,14 @@ const ManageOrganization = () => {
|
|||||||
</Label>
|
</Label>
|
||||||
<input className="form-control form-control-sm" />
|
<input className="form-control form-control-sm" />
|
||||||
</div>
|
</div>
|
||||||
|
<div className="mb-1 text-start">
|
||||||
|
<SelectMultiple
|
||||||
|
name="serviceIds"
|
||||||
|
label="Services"
|
||||||
|
required={true}
|
||||||
|
valueKey="id"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div className="mb-1 text-start">
|
<div className="mb-1 text-start">
|
||||||
<Label htmlFor="organization" required>
|
<Label htmlFor="organization" required>
|
||||||
Address
|
Address
|
||||||
@ -66,7 +75,7 @@ const ManageOrganization = () => {
|
|||||||
isOpen={orgModal.isOpen}
|
isOpen={orgModal.isOpen}
|
||||||
onClose={orgModal.onClose}
|
onClose={orgModal.onClose}
|
||||||
onSubmit={onSubmit}
|
onSubmit={onSubmit}
|
||||||
title={"Manage organization"}
|
title={"Manage Organization"}
|
||||||
actionLabel={"Submit"}
|
actionLabel={"Submit"}
|
||||||
body={contentBody}
|
body={contentBody}
|
||||||
/>
|
/>
|
||||||
|
@ -2,15 +2,17 @@ import React, { useState, useEffect, useRef } from "react";
|
|||||||
import { useFormContext } from "react-hook-form";
|
import { useFormContext } from "react-hook-form";
|
||||||
import { createPortal } from "react-dom";
|
import { createPortal } from "react-dom";
|
||||||
import "./MultiSelectDropdown.css";
|
import "./MultiSelectDropdown.css";
|
||||||
|
import Label from "./Label";
|
||||||
|
|
||||||
const SelectMultiple = ({
|
const SelectMultiple = ({
|
||||||
name,
|
name,
|
||||||
options = [],
|
options = [],
|
||||||
label = "Select options",
|
label = "Select options",
|
||||||
labelKey = "name", // Can now be a function or a string
|
labelKey = "name",
|
||||||
valueKey = "id",
|
valueKey = "id",
|
||||||
placeholder = "Please select...",
|
placeholder = "Please select...",
|
||||||
IsLoading = false,
|
IsLoading = false,
|
||||||
|
required = false,
|
||||||
}) => {
|
}) => {
|
||||||
const { setValue, watch } = useFormContext();
|
const { setValue, watch } = useFormContext();
|
||||||
const selectedValues = watch(name) || [];
|
const selectedValues = watch(name) || [];
|
||||||
@ -20,7 +22,11 @@ const SelectMultiple = ({
|
|||||||
const containerRef = useRef(null);
|
const containerRef = useRef(null);
|
||||||
const dropdownRef = useRef(null);
|
const dropdownRef = useRef(null);
|
||||||
|
|
||||||
const [dropdownStyles, setDropdownStyles] = useState({ top: 0, left: 0, width: 0 });
|
const [dropdownStyles, setDropdownStyles] = useState({
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
width: 0,
|
||||||
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleClickOutside = (e) => {
|
const handleClickOutside = (e) => {
|
||||||
@ -100,8 +106,14 @@ const SelectMultiple = ({
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={valueVal}
|
key={valueVal}
|
||||||
className={`multi-select-dropdown-option ${isChecked ? "selected" : ""}`}
|
className={`multi-select-dropdown-option ${
|
||||||
style={{ display: "flex", alignItems: "center", padding: "4px 8px" }}
|
isChecked ? "selected" : ""
|
||||||
|
}`}
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
padding: "4px 8px",
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
@ -130,8 +142,14 @@ const SelectMultiple = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div ref={containerRef} className="multi-select-dropdown-container" style={{ position: "relative" }}>
|
<div
|
||||||
<label className="form-label mb-1">{label}</label>
|
ref={containerRef}
|
||||||
|
className="multi-select-dropdown-container"
|
||||||
|
style={{ position: "relative" }}
|
||||||
|
>
|
||||||
|
<Label htmlFor={name} required={required}>
|
||||||
|
{label}
|
||||||
|
</Label>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
className="multi-select-dropdown-header"
|
className="multi-select-dropdown-header"
|
||||||
@ -140,7 +158,9 @@ const SelectMultiple = ({
|
|||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
className={
|
className={
|
||||||
selectedValues.length > 0 ? "placeholder-style-selected" : "placeholder-style"
|
selectedValues.length > 0
|
||||||
|
? "placeholder-style-selected"
|
||||||
|
: "placeholder-style"
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<div className="selected-badges-container">
|
<div className="selected-badges-container">
|
||||||
@ -149,7 +169,10 @@ const SelectMultiple = ({
|
|||||||
const found = options.find((opt) => opt[valueKey] === val);
|
const found = options.find((opt) => opt[valueKey] === val);
|
||||||
const label = found ? getLabel(found) : "";
|
const label = found ? getLabel(found) : "";
|
||||||
return (
|
return (
|
||||||
<span key={val} className="badge badge-selected-item mx-1 mb-1">
|
<span
|
||||||
|
key={val}
|
||||||
|
className="badge badge-selected-item mx-1 mb-1"
|
||||||
|
>
|
||||||
{label}
|
{label}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user