Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/sidebar refactor #75

Merged
merged 33 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2705602
fix: ui problems
timothyrusso Jan 4, 2024
161ed16
feat: add sidebar to storybook
timothyrusso Jan 4, 2024
98af998
Merge remote-tracking branch 'origin/dev' into feature/sidebar-refactor
timothyrusso Jan 11, 2024
08d31ad
Merge branch 'dev' into feature/sidebar-refactor
Dan-Y-Ko Jan 12, 2024
9edfefe
feat: add custom button to the sidebar
Jan 12, 2024
24627a2
fix button ui problem
timothyrusso Jan 12, 2024
724d285
fix: import issue
timothyrusso Jan 13, 2024
6d21769
Merge remote-tracking branch 'origin/dev' into feature/sidebar-refactor
timothyrusso Jan 15, 2024
851e748
feat: update user check for my voyage pages
timothyrusso Jan 15, 2024
81496d1
fix: lint errors
timothyrusso Jan 15, 2024
b810ce6
fix: prettier
timothyrusso Jan 16, 2024
2997d79
Merge branch 'dev' into feature/sidebar-refactor
Dan-Y-Ko Jan 18, 2024
1b32fc3
feat: use neutral variant and remove unused classnames
timothyrusso Jan 21, 2024
e448dae
fix: lint errors
timothyrusso Jan 21, 2024
84477ac
feat: voyage icons alignment
timothyrusso Jan 21, 2024
89b8710
update colors for neutral variant in button component
Dan-Y-Ko Jan 21, 2024
767115f
Merge remote-tracking branch 'origin/dev' into feature/sidebar-refactor
timothyrusso Jan 23, 2024
67931a1
fix: selected button when current path change
timothyrusso Jan 23, 2024
69435fd
Merge branch 'feature/sidebar-refactor' of https://github.com/chingu-…
timothyrusso Jan 23, 2024
d3c44d0
Merge remote-tracking branch 'origin/dev' into feature/sidebar-refactor
timothyrusso Jan 25, 2024
7e9e5e8
fix: remove unused classes
timothyrusso Jan 25, 2024
253452c
feat: remove unused hook
timothyrusso Jan 25, 2024
f48ae24
fix: lint errors
timothyrusso Jan 25, 2024
f46a0b4
feat: remove usless check on sidebar page
timothyrusso Jan 25, 2024
becba89
feat: add check for the voyage status
timothyrusso Jan 26, 2024
9fea9a3
fix: storybook error
timothyrusso Jan 26, 2024
c803874
fix: push error
timothyrusso Jan 26, 2024
344d45f
style: remove unused comments
timothyrusso Jan 26, 2024
f6c189a
Merge remote-tracking branch 'origin/dev' into feature/sidebar-refactor
timothyrusso Jan 28, 2024
84d6e6c
fix: pr comments
timothyrusso Jan 28, 2024
5ee4162
fix: pr comments
timothyrusso Jan 29, 2024
6417bd6
fix: pr comments
timothyrusso Jan 30, 2024
8f8b9d9
style: lint formatting
timothyrusso Jan 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const nextConfig = {
hostname: "gravatar.com"
}
]
},
experimental: {
serverActions: true
}
};

Expand Down
5 changes: 4 additions & 1 deletion src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,16 @@ export default function Button({
variant,
size,
outline,
children,
...props
}: ButtonProps) {
return (
<button
type="button"
className={cn(button({ variant, size, outline, className }))}
{...props}
/>
>
{children}
</button>
);
}
2 changes: 1 addition & 1 deletion src/components/navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface NavbarProps {

export default function Navbar({ children }: NavbarProps) {
return (
<nav className="navbar bg-base-100">
<nav className="navbar flex bg-base-100 h-[75px]">
<div className="flex-1 pl-2">
<ChinguMenu />
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/sidebar/ExpandButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function ExpandButton({ isOpen, onClick }: ExpandButtonProps) {
return (
<button
type="button"
className="w-[3.125rem] bg-base-200 text-base-300 capitalize hover:bg-base-200 mr-2 border-none"
className="bg-base-200 text-base-300 capitalize hover:bg-base-200 border-none"
onClick={() => onClick(!isOpen)}
>
{isOpen ? (
Expand Down
13 changes: 7 additions & 6 deletions src/components/sidebar/PageButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Link from "next/link";
import { usePathname } from "next/navigation";
import { MainPages, PageProperty, voyagePages } from "./Sidebar";
import Button from "@/components/Button";

interface PageButtonProps {
element: PageProperty;
Expand All @@ -23,8 +24,8 @@ export default function PageButton({
const buttonStyles = `${
isOpen
? "w-[14.375rem] flex justify-start pl-6"
: "w-[3.125rem] tooltip hover:tooltip-open tooltip-right before:bg-base-100 before:text-base-300 after:border-r-base-100 overflow:false"
} h-[3.125rem] text-base-300 capitalize border-none hover:bg-base-100`;
: "w-[3.125rem] tooltip hover:tooltip-open tooltip-right before:bg-base-100 before:text-base-300 after:border-r-base-100 overflow:false px-0"
} h-[3.125rem] text-base-300 capitalize border-none hover:bg-base-100 active:bg-neutral-content focus:bg-neutral-content focus:text-base-300`;

const getButtonBackgroundStyle = (page: string) =>
(selectedButton === page && selectedButton === currentPath) ||
Expand All @@ -38,26 +39,26 @@ export default function PageButton({
return (
<li>
<Link
href={element.name !== MainPages.myVoyage ? link : ""}
href={element.name !== MainPages.myVoyage ? link : "#"}
className={
element.name === MainPages.myVoyage && isOpen
? "cursor-default pointer-events-none"
: ""
}
>
<button
<Button
type="button"
data-tip={element.name}
className={`${buttonStyles} ${getButtonBackgroundStyle(
element.link,
)} ${element.marginBottom}`}
)} ${element.marginBottom} flex items-center`}
onMouseEnter={() => setHoveredButton(element.name)}
onMouseLeave={() => setHoveredButton(null)}
onClick={() => onClick(element)}
>
{element.icon}
{getButtonText(element.name)}
</button>
</Button>
</Link>
</li>
);
Expand Down
45 changes: 29 additions & 16 deletions src/components/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { useState } from "react";
import { useCallback, useState } from "react";
import type React from "react";
import { usePathname } from "next/navigation";
import {
Expand All @@ -12,6 +12,9 @@ import {
import PageButton from "./PageButton";
import VoyagePageButton from "./VoyagePageButton";
import ExpandButton from "./ExpandButton";
import { useAppSelector } from "@/store/hooks";
import { VoyageTeamMembers } from "@/store/features/user/userSlice";
import { RootState } from "@/store/store";

export enum MainPages {
dashboard = "Dashboard",
Expand Down Expand Up @@ -95,32 +98,42 @@ const pagesProperties: PageProperty[] = [
},
];

//-- Mocked fake data just for testing purpose --//
const isVoyageStarted: boolean = true;
//-- --//

export default function Sidebar() {
const currentPath = usePathname();

const [isOpenSidebar, setIsOpenSidebar] = useState<boolean>(true);
const [selectedButton, setSelectedButton] = useState<string>(currentPath);
const [hoveredButton, setHoveredButton] = useState<string | null>(null);

const handlePageClick = (element: PageProperty | string) => {
if (typeof element === "string") {
setSelectedButton(element);
} else if (element.name === MainPages.myVoyage) {
setIsOpenSidebar(true);
} else {
setSelectedButton(element.link);
}
};
const { isAuthenticated } = useAppSelector(
(state: RootState): { isAuthenticated: boolean } => state.auth,
);
const { voyageTeamMembers } = useAppSelector(
(state: RootState): { voyageTeamMembers: VoyageTeamMembers[] } =>
state.user,
);

const isVoyageStarted: boolean =
isAuthenticated && !!voyageTeamMembers[0]?.id;

const handlePageClick = useCallback(
(element: PageProperty | string) => {
if (typeof element === "string") {
setSelectedButton(element);
} else if (element.name === MainPages.myVoyage) {
setIsOpenSidebar(true);
} else {
setSelectedButton(element.link);
}
},
[setSelectedButton, setIsOpenSidebar],
);

return (
<aside
className={`${
isOpenSidebar ? "w-[18.438rem]" : "w-[5.813rem]"
} text-center bg-base-200 flex flex-col justify-between border-r border-neutral-content shadow-[4px_4px_4px_0] shadow-neutral-focus/5`}
} text-center bg-base-200 flex flex-col justify-between border-r border-neutral-content shadow-[4px_4px_4px_0] shadow-neutral-focus/5 h-full`}
>
<ul
className={`flex flex-col ${
Expand Down Expand Up @@ -154,7 +167,7 @@ export default function Sidebar() {
</ul>
)}
</ul>
<div className="flex flex-col items-end justify-start border-t border-neutral-content">
<div className="flex flex-col items-end justify-start border-t border-neutral-content min-h-[80px] pt-4 pr-6">
<ExpandButton isOpen={isOpenSidebar} onClick={setIsOpenSidebar} />
</div>
</aside>
Expand Down
2 changes: 1 addition & 1 deletion src/store/features/user/userSlice.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PayloadAction, createSlice } from "@reduxjs/toolkit";

interface VoyageTeamMembers {
export interface VoyageTeamMembers {
id: number;
voyageTeamId: number;
voyageTeam: {
Expand Down
23 changes: 23 additions & 0 deletions src/stories/components/Sidebar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { Meta, StoryObj } from "@storybook/react";
import Sidebar from "@/components/sidebar/Sidebar";

const meta: Meta<typeof Sidebar> = {
title: "Example/Sidebar",
component: Sidebar,
decorators: [
(Story) => (
<div style={{ height: 700 }}>
<Story />
</div>
),
],
parameters: {
layout: "fullscreen",
},
tags: ["autodocs"],
};

export default meta;
type Story = StoryObj<typeof meta>;

export const Default: Story = {};
Loading