Moving files and rename some of them.

This commit is contained in:
charles-gauthereau
2024-12-16 16:30:00 +01:00
parent c97d68d697
commit 31ee81c10f
75 changed files with 64 additions and 175 deletions
@@ -0,0 +1,71 @@
"use client"
import {useEffect, useState} from "react";
import {ComboBox} from "@/components/wrappers/common/combobox";
import {Organization} from "@prisma/client";
import {getCurrentOrganizationSlug, setCurrentOrganizationSlug} from "@/features/dashboard/organization-cookie";
import {useSidebar} from "@/components/ui/sidebar";
export type organizationComboBoxProps = {
organizations: Organization[]
defaultOrganization: Organization
}
export function OrganizationCombobox(props: organizationComboBoxProps) {
// const {organizationId, moveToAnotherOrganization} = useStore((state) => state);
const [organizationSlug, setOrganizationSlug] = useState<string>()
const {organizations, defaultOrganization} = props
useEffect(() => {
getCurrentOrganizationSlug().then(slug => {
if (slug == "") {
setOrganizationSlug(defaultOrganization.slug)
setCurrentOrganizationSlug(defaultOrganization.slug)
} else {
setOrganizationSlug(slug)
const organization = organizations.find(organization => organization.slug === slug)
if (!organization) {
setOrganizationSlug(defaultOrganization.slug)
setCurrentOrganizationSlug(defaultOrganization.slug)
}
}
})
}, [organizationSlug])
const values = organizations.map(organization => {
return ({
value: organization.slug,
label: organization.name,
})
})
const onValueChange = (slug: string) => {
if (organizationSlug !== slug) {
setOrganizationSlug(slug)
setCurrentOrganizationSlug(slug)
}
}
const { state, isMobile } = useSidebar();
return (
<>
{state === 'expanded' && (
<ComboBox
sideBar
values={values}
defaultValue={organizationSlug}
onValueChange={onValueChange}/>
)}
</>
)
}