Compare commits

...

3 Commits

7 changed files with 64 additions and 64 deletions

View File

@@ -44,7 +44,7 @@ export default function WorkspaceMenu({
</span> </span>
<span <span
className={twMerge( className={twMerge(
"ml-2 text-sm font-bold text-neutral-900 dark:text-dark-1000", "ml-2 truncate text-sm font-bold text-neutral-900 dark:text-dark-1000",
isCollapsed && "md:hidden", isCollapsed && "md:hidden",
)} )}
> >
@@ -87,17 +87,17 @@ export default function WorkspaceMenu({
onClick={() => switchWorkspace(availableWorkspace)} onClick={() => switchWorkspace(availableWorkspace)}
className="flex w-full items-center justify-between rounded-[5px] px-3 py-2 text-left text-sm text-neutral-900 hover:bg-light-200 dark:text-dark-1000 dark:hover:bg-dark-400" className="flex w-full items-center justify-between rounded-[5px] px-3 py-2 text-left text-sm text-neutral-900 hover:bg-light-200 dark:text-dark-1000 dark:hover:bg-dark-400"
> >
<div> <div className="flex min-w-0 flex-1 items-center">
<span className="inline-flex h-5 w-5 items-center justify-center rounded-[5px] bg-indigo-700"> <span className="inline-flex h-5 w-5 flex-shrink-0 items-center justify-center rounded-[5px] bg-indigo-700">
<span className="text-xs font-medium leading-none text-white"> <span className="text-xs font-medium leading-none text-white">
{availableWorkspace.name.charAt(0).toUpperCase()} {availableWorkspace.name.charAt(0).toUpperCase()}
</span> </span>
</span> </span>
<span className="ml-2 text-xs font-medium"> <span className="ml-2 truncate text-xs font-medium">
{availableWorkspace.name} {availableWorkspace.name}
</span> </span>
</div> </div>
{workspace.name === availableWorkspace.name && ( {workspace.publicId === availableWorkspace.publicId && (
<span> <span>
<HiCheck className="h-4 w-4" aria-hidden="true" /> <HiCheck className="h-4 w-4" aria-hidden="true" />
</span> </span>

View File

@@ -1,4 +1,4 @@
import { createContext, useContext, useState } from "react"; import { createContext, useCallback, useContext, useState } from "react";
interface ModalState { interface ModalState {
contentType: string; contentType: string;
@@ -42,57 +42,59 @@ export const ModalProvider: React.FC<Props> = ({ children }) => {
const entityId = currentModal?.entityId || ""; const entityId = currentModal?.entityId || "";
const entityLabel = currentModal?.entityLabel || ""; const entityLabel = currentModal?.entityLabel || "";
const openModal = ( const openModal = useCallback(
contentType: string, (contentType: string, entityId?: string, entityLabel?: string) => {
entityId?: string, const newModal: ModalState = { contentType, entityId, entityLabel };
entityLabel?: string, setModalStack((prev) => [...prev, newModal]);
) => { },
const newModal: ModalState = { contentType, entityId, entityLabel }; [],
setModalStack((prev) => [...prev, newModal]); );
};
const closeModal = () => { const closeModal = useCallback(() => {
setModalStack((prev) => { setModalStack((prev) => {
if (prev.length <= 1) { if (prev.length <= 1) {
return []; return [];
} }
return prev.slice(0, -1); return prev.slice(0, -1);
}); });
}; }, []);
const closeModals = (count: number) => { const closeModals = useCallback((count: number) => {
setModalStack(prev => { setModalStack((prev) => {
const newLength = Math.max(0, prev.length - count); const newLength = Math.max(0, prev.length - count);
return prev.slice(0, newLength); return prev.slice(0, newLength);
}); });
}; }, []);
const clearAllModals = () => { const clearAllModals = useCallback(() => {
setModalStack([]); setModalStack([]);
}; }, []);
const setModalState = (modalType: string, state: any) => { const setModalState = useCallback((modalType: string, state: any) => {
setModalStates((prev) => ({ setModalStates((prev) => ({
...prev, ...prev,
[modalType]: state, [modalType]: state,
})); }));
}; }, []);
const getModalState = (modalType: string) => { const getModalState = useCallback(
return modalStates[modalType]; (modalType: string) => {
}; return modalStates[modalType];
},
[modalStates],
);
const clearModalState = (modalType: string) => { const clearModalState = useCallback((modalType: string) => {
setModalStates((prev) => { setModalStates((prev) => {
const newStates = { ...prev }; const newStates = { ...prev };
delete newStates[modalType]; delete newStates[modalType];
return newStates; return newStates;
}); });
}; }, []);
const clearAllModalStates = () => { const clearAllModalStates = useCallback(() => {
setModalStates({}); setModalStates({});
}; }, []);
return ( return (
<ModalContext.Provider <ModalContext.Provider

View File

@@ -47,12 +47,16 @@ export const WorkspaceProvider: React.FC<{ children: ReactNode }> = ({
const [hasLoaded, setHasLoaded] = useState(false); const [hasLoaded, setHasLoaded] = useState(false);
const { data, isLoading } = api.workspace.all.useQuery(); const { data, isLoading } = api.workspace.all.useQuery();
const utils = api.useUtils();
const switchWorkspace = (_workspace: Workspace) => { const switchWorkspace = (_workspace: Workspace) => {
localStorage.setItem("workspacePublicId", _workspace.publicId); localStorage.setItem("workspacePublicId", _workspace.publicId);
setWorkspace(_workspace); setWorkspace(_workspace);
// Refetch workspace data to ensure availableWorkspaces is up to date
void utils.workspace.all.refetch();
router.push(`/boards`); router.push(`/boards`);
}; };
@@ -66,21 +70,15 @@ export const WorkspaceProvider: React.FC<{ children: ReactNode }> = ({
localStorage.getItem("workspacePublicId"); localStorage.getItem("workspacePublicId");
if (data.length) { if (data.length) {
const workspaces = data const workspaces = data.map(({ workspace, role }) => ({
.map(({ workspace, role }) => { role,
if (!workspace) return; publicId: workspace.publicId,
name: workspace.name,
return { slug: workspace.slug,
role, description: workspace.description,
publicId: workspace.publicId, plan: workspace.plan,
name: workspace.name, hasLoaded: true,
slug: workspace.slug, })) as Workspace[];
description: workspace.description,
plan: workspace.plan,
hasLoaded: true,
};
})
.filter((workspace) => workspace !== null) as Workspace[];
if (workspaces.length) setAvailableWorkspaces(workspaces); if (workspaces.length) setAvailableWorkspaces(workspaces);
} }
@@ -116,7 +114,7 @@ export const WorkspaceProvider: React.FC<{ children: ReactNode }> = ({
role: primaryWorkspaceRole, role: primaryWorkspaceRole,
}); });
} }
}, [data]); }, [data, isLoading]);
return ( return (
<WorkspaceContext.Provider <WorkspaceContext.Provider

View File

@@ -1,4 +1,5 @@
import { t } from "@lingui/core/macro"; import { t } from "@lingui/core/macro";
import { useEffect } from "react";
import { HiArrowDownTray, HiOutlinePlusSmall } from "react-icons/hi2"; import { HiArrowDownTray, HiOutlinePlusSmall } from "react-icons/hi2";
import Button from "~/components/Button"; import Button from "~/components/Button";
@@ -16,7 +17,11 @@ export default function BoardsPage() {
const { openModal, modalContentType, isOpen } = useModal(); const { openModal, modalContentType, isOpen } = useModal();
const { availableWorkspaces, workspace, hasLoaded } = useWorkspace(); const { availableWorkspaces, workspace, hasLoaded } = useWorkspace();
if (hasLoaded && availableWorkspaces.length === 0) openModal("NEW_WORKSPACE"); useEffect(() => {
if (hasLoaded && availableWorkspaces.length === 0) {
openModal("NEW_WORKSPACE");
}
}, [hasLoaded, availableWorkspaces.length, openModal]);
return ( return (
<> <>

View File

@@ -1,4 +1,3 @@
import { Menu } from "@headlessui/react";
import { t } from "@lingui/core/macro"; import { t } from "@lingui/core/macro";
import { HiMiniPlus } from "react-icons/hi2"; import { HiMiniPlus } from "react-icons/hi2";
@@ -101,22 +100,19 @@ export default function LabelSelector({
{selectedLabels.length ? ( {selectedLabels.length ? (
<div className="flex flex-wrap gap-x-0.5"> <div className="flex flex-wrap gap-x-0.5">
{selectedLabels.map((label) => ( {selectedLabels.map((label) => (
<Menu.Button key={label.key}>
<Badge value={label.value} iconLeft={label.leftIcon} />
</Menu.Button>
))}
<Menu.Button>
<Badge <Badge
value={t`Add label`} key={label.key}
iconLeft={<HiMiniPlus size={14} />} value={label.value}
iconLeft={label.leftIcon}
/> />
</Menu.Button> ))}
<Badge value={t`Add label`} iconLeft={<HiMiniPlus size={14} />} />
</div> </div>
) : ( ) : (
<Menu.Button className="flex h-full w-full items-center rounded-[5px] border-[1px] border-light-50 pl-2 text-left text-sm text-neutral-900 hover:border-light-300 hover:bg-light-200 dark:border-dark-50 dark:text-dark-1000 dark:hover:border-dark-200 dark:hover:bg-dark-100"> <div className="flex h-full w-full items-center rounded-[5px] border-[1px] border-light-50 pl-2 text-left text-sm text-neutral-900 hover:border-light-300 hover:bg-light-200 dark:border-dark-50 dark:text-dark-1000 dark:hover:border-dark-200 dark:hover:bg-dark-100">
<HiMiniPlus size={22} className="pr-2" /> <HiMiniPlus size={22} className="pr-2" />
{t`Add label`} {t`Add label`}
</Menu.Button> </div>
)} )}
</CheckboxDropdown> </CheckboxDropdown>
)} )}

View File

@@ -1,4 +1,3 @@
import { Menu } from "@headlessui/react";
import { t } from "@lingui/core/macro"; import { t } from "@lingui/core/macro";
import CheckboxDropdown from "~/components/CheckboxDropdown"; import CheckboxDropdown from "~/components/CheckboxDropdown";
@@ -79,9 +78,9 @@ export default function ListSelector({
}} }}
asChild asChild
> >
<Menu.Button className="flex h-full w-full items-center rounded-[5px] border-[1px] border-light-50 py-1 pl-2 text-left text-sm text-neutral-900 hover:border-light-300 hover:bg-light-200 dark:border-dark-50 dark:text-dark-1000 dark:hover:border-dark-200 dark:hover:bg-dark-100"> <div className="flex h-full w-full items-center rounded-[5px] border-[1px] border-light-50 py-1 pl-2 text-left text-sm text-neutral-900 hover:border-light-300 hover:bg-light-200 dark:border-dark-50 dark:text-dark-1000 dark:hover:border-dark-200 dark:hover:bg-dark-100">
{selectedList?.value} {selectedList?.value}
</Menu.Button> </div>
</CheckboxDropdown> </CheckboxDropdown>
)} )}
</> </>

View File

@@ -1,5 +1,4 @@
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { Menu } from "@headlessui/react";
import { t } from "@lingui/core/macro"; import { t } from "@lingui/core/macro";
import { HiMiniPlus } from "react-icons/hi2"; import { HiMiniPlus } from "react-icons/hi2";
@@ -112,11 +111,12 @@ export default function MemberSelector({
createNewItemLabel={t`Invite member`} createNewItemLabel={t`Invite member`}
asChild asChild
> >
<Menu.Button className="flex h-full w-full items-center rounded-[5px] border-[1px] border-light-50 py-1 pl-2 text-left text-sm text-neutral-900 hover:border-light-300 hover:bg-light-200 dark:border-dark-50 dark:text-dark-1000 dark:hover:border-dark-200 dark:hover:bg-dark-100"> <div className="flex h-full w-full items-center rounded-[5px] border-[1px] border-light-50 py-1 pl-2 text-left text-sm text-neutral-900 hover:border-light-300 hover:bg-light-200 dark:border-dark-50 dark:text-dark-1000 dark:hover:border-dark-200 dark:hover:bg-dark-100">
{selectedMembers.length ? ( {selectedMembers.length ? (
<div className="isolate flex justify-end -space-x-1 overflow-hidden"> <div className="isolate flex justify-end -space-x-1 overflow-hidden">
{selectedMembers.map(({ value, imageUrl }) => ( {selectedMembers.map(({ value, imageUrl }) => (
<Avatar <Avatar
key={value}
size="sm" size="sm"
name={value} name={value}
imageUrl={imageUrl} imageUrl={imageUrl}
@@ -130,7 +130,7 @@ export default function MemberSelector({
{t`Add member`} {t`Add member`}
</> </>
)} )}
</Menu.Button> </div>
</CheckboxDropdown> </CheckboxDropdown>
)} )}
</> </>