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

Refactor/sidebar #1441

Merged
merged 72 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
8abcdc8
refactor(sidebar): add very basic shadcn sidebar
rockingrohit9639 Nov 20, 2024
875b8c2
refactor(sidebar): add organization-selector in sidebar
rockingrohit9639 Nov 20, 2024
c315109
refactor(sidebar): fix organization-selector on mobile
rockingrohit9639 Nov 21, 2024
47879a8
refactor(sidebar): create user menu for sidebar
rockingrohit9639 Nov 21, 2024
5cff467
refactor(sidebar): create basic sidebar nav menu
rockingrohit9639 Nov 21, 2024
b992707
refactor(sidebar): create main and bottom navigation for sidebar
rockingrohit9639 Nov 21, 2024
882e5ae
refactor(sidebar): fix icons sized for collapsed sidebar issue
rockingrohit9639 Nov 21, 2024
692bf95
refactor(sidebar): close dropdown on click
rockingrohit9639 Nov 21, 2024
44a6f8c
refactor(sidebar): fix issue with organization switching atom
rockingrohit9639 Nov 21, 2024
d25edff
refactor(sidebar): highlight active route in sidebar menu
rockingrohit9639 Nov 21, 2024
c8f6595
Merge branch 'main' into refactor/sidebar
DonKoko Nov 22, 2024
ae421ac
refactor(sidebar): fix pr issues
rockingrohit9639 Nov 22, 2024
e5eb1c7
refactor(sidebar): fix color issues and implement sidebar with cookie…
rockingrohit9639 Nov 23, 2024
a6fee1a
refactor(sidebar): add very basic shadcn sidebar
rockingrohit9639 Nov 20, 2024
b167da2
refactor(sidebar): add organization-selector in sidebar
rockingrohit9639 Nov 20, 2024
5a115d8
refactor(sidebar): fix organization-selector on mobile
rockingrohit9639 Nov 21, 2024
5bac31f
refactor(sidebar): create user menu for sidebar
rockingrohit9639 Nov 21, 2024
86ac496
refactor(sidebar): create basic sidebar nav menu
rockingrohit9639 Nov 21, 2024
396ade0
refactor(sidebar): create main and bottom navigation for sidebar
rockingrohit9639 Nov 21, 2024
95c4d87
refactor(sidebar): fix icons sized for collapsed sidebar issue
rockingrohit9639 Nov 21, 2024
dd64b96
refactor(sidebar): close dropdown on click
rockingrohit9639 Nov 21, 2024
a7f7aaa
refactor(sidebar): fix issue with organization switching atom
rockingrohit9639 Nov 21, 2024
198fa2c
refactor(sidebar): highlight active route in sidebar menu
rockingrohit9639 Nov 21, 2024
01fb3a0
refactor(sidebar): fix pr issues
rockingrohit9639 Nov 22, 2024
9be30ee
refactor(sidebar): fix color issues and implement sidebar with cookie…
rockingrohit9639 Nov 23, 2024
0fcf89f
Merge branch 'main' into refactor/sidebar
DonKoko Nov 26, 2024
8648245
Merge branch 'refactor/sidebar' of github.com:rockingrohit9639/shelf.…
rockingrohit9639 Nov 26, 2024
968757a
Merge branch 'main' of github.com:Shelf-nu/shelf.nu into refactor/sid…
rockingrohit9639 Nov 27, 2024
a5f5215
refactor(sidebar): done pr review changes
rockingrohit9639 Nov 27, 2024
036d7a9
Merge branch 'main' into refactor/sidebar
DonKoko Nov 28, 2024
8032f1c
feat(404): add additionalData in getAsset for special case
rockingrohit9639 Nov 19, 2024
be81ec1
feat(special-error): create UI for handling special error cases
rockingrohit9639 Nov 19, 2024
9e82e8d
pr review changes
rockingrohit9639 Nov 20, 2024
ad2dda3
feat(improve-404): fix pr review issues
rockingrohit9639 Nov 22, 2024
64b954a
feat(improve-404): add request in getAsset for proper redirecting
rockingrohit9639 Nov 23, 2024
473f9f5
feat(improve-404): update getKit function to make it more generic
rockingrohit9639 Nov 23, 2024
c226fcc
feat(improve-404): improve 404 handling for kit
rockingrohit9639 Nov 25, 2024
6847db2
feat(improve-404): improve 404 handling for location
rockingrohit9639 Nov 26, 2024
f364016
feature(workflow): create separate function for team with 404 handling
rockingrohit9639 Nov 26, 2024
0ea567a
feat(improve-404): handling special case of multiple organization for…
rockingrohit9639 Nov 26, 2024
6d63a76
feat(improve-404): fix style issue on ErrorBoundary for team settings
rockingrohit9639 Nov 27, 2024
91074dd
feat(improve-404): improve 404 handling for bookings
rockingrohit9639 Nov 27, 2024
2044b7f
styling adjustments
DonKoko Nov 28, 2024
873df4d
refactor(sidebar): remove unsed files
rockingrohit9639 Nov 29, 2024
b7c0642
refactor(sidebar): fix eslint issues
rockingrohit9639 Nov 29, 2024
6f830a5
refactor(sidebar): adjust padding on assets index page and add label …
rockingrohit9639 Nov 29, 2024
359ae32
refactor(sidebar): move question/feedback from dropdown to sidebar
rockingrohit9639 Nov 29, 2024
0c95a51
refactor(sidebar): navigating to first child route on parent button c…
rockingrohit9639 Nov 29, 2024
712f71b
Merge branch 'main' of github.com:Shelf-nu/shelf.nu into refactor/sid…
rockingrohit9639 Nov 29, 2024
f53eb0c
refactor(sidebar): replace all sidebar icons with lucide-icons
rockingrohit9639 Nov 29, 2024
e1b3c20
refactor(sidebar): handling disabled state in sidebar menu
rockingrohit9639 Nov 29, 2024
1328db0
Merge branch 'main' into refactor/sidebar
DonKoko Dec 2, 2024
a3627f2
styling adjustments
DonKoko Dec 2, 2024
932f5cc
Merge branch 'main' into refactor/sidebar
DonKoko Dec 3, 2024
b36c2f3
Merge branch 'main' of github.com:Shelf-nu/shelf.nu into refactor/sid…
rockingrohit9639 Dec 3, 2024
d409fd3
Merge branch 'refactor/sidebar' of github.com:rockingrohit9639/shelf.…
rockingrohit9639 Dec 3, 2024
6c5659b
fix merge conflicts
rockingrohit9639 Dec 3, 2024
c27973b
refactor(sidebar): fix pr review issues
rockingrohit9639 Dec 4, 2024
4e93014
Merge branch 'main' of github.com:Shelf-nu/shelf.nu into refactor/sid…
rockingrohit9639 Dec 4, 2024
02dd97e
Merge branch 'main' into refactor/sidebar
DonKoko Dec 5, 2024
25f8b73
style adjustments
DonKoko Dec 5, 2024
e4a77ca
refactor(sidebar): fix height issue on auth pages, create helper for …
rockingrohit9639 Dec 6, 2024
0884fea
Merge branch 'refactor/sidebar' of github.com:rockingrohit9639/shelf.…
rockingrohit9639 Dec 6, 2024
42fa28a
Merge branch 'main' of github.com:Shelf-nu/shelf.nu into refactor/sid…
rockingrohit9639 Dec 6, 2024
4c331d5
Merge branch 'main' into refactor/sidebar
DonKoko Dec 9, 2024
30c9027
refactor(sidebar): fix issue with conditional hook call
rockingrohit9639 Dec 9, 2024
12abab8
Merge branch 'refactor/sidebar' of github.com:rockingrohit9639/shelf.…
rockingrohit9639 Dec 9, 2024
79354a0
refactor(sidebar): add sidebar notice card
rockingrohit9639 Dec 9, 2024
725515d
refactor(sidebar): update use-mobile hook
rockingrohit9639 Dec 9, 2024
4ab2a77
Merge branch 'main' into refactor/sidebar
DonKoko Dec 10, 2024
2049e6a
ui fixes
DonKoko Dec 10, 2024
1756f7b
mend
DonKoko Dec 10, 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
12 changes: 5 additions & 7 deletions app/components/assets/assets-index/asset-index-pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useState } from "react";
import { useFetcher, useRouteLoaderData } from "@remix-run/react";
import { useFetcher } from "@remix-run/react";
import { AlertIcon, ChevronRight } from "~/components/icons/library";
import { useSidebar } from "~/components/layout/sidebar/sidebar";
import {
AlertDialog,
AlertDialogCancel,
Expand All @@ -16,7 +17,6 @@ import { useAssetIndexViewState } from "~/hooks/use-asset-index-view-state";

import { useViewportHeight } from "~/hooks/use-viewport-height";
import { useUserRoleHelper } from "~/hooks/user-user-role-helper";
import type { loader as layoutLoader } from "~/routes/_layout+/_layout";
import {
PermissionAction,
PermissionEntity,
Expand All @@ -29,11 +29,9 @@ import { ButtonGroup } from "../../shared/button-group";

export function AssetIndexPagination() {
const { roles } = useUserRoleHelper();
let minimizedSidebar = useRouteLoaderData<typeof layoutLoader>(
"routes/_layout+/_layout"
)?.minimizedSidebar;
const fetcher = useFetcher({ key: "asset-index-settings-mode" });
const { isMd } = useViewportHeight();
const { state } = useSidebar();

const { modeIsSimple, modeIsAdvanced } = useAssetIndexViewState();
const disabledButtonStyles =
Expand All @@ -57,9 +55,9 @@ export function AssetIndexPagination() {
return (
<div
className={tw(
"asset-index-pagination flex flex-col items-center justify-between border-t border-gray-200 bg-white transition-all delay-75 ease-in-out md:flex-row",
isMd ? "fixed bottom-0 right-0 z-[12]" : "",
"asset-index-pagination flex flex-col items-center justify-between border-t border-gray-200 bg-white md:flex-row ",
minimizedSidebar ? "lg:left-[82px]" : "lg:left-[312px]"
state === "collapsed" ? "lg:left-[48px]" : "lg:left-[256px]"
)}
>
<Pagination className="px-4 py-[6px]" />
Expand Down
1 change: 1 addition & 0 deletions app/components/errors/error-404-handler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function Error404Handler({
case "asset":
case "kit":
case "location":

case "booking":
case "customField": {
const modelLabel = getModelLabelForEnumValue(additionalData.model);
Expand Down
48 changes: 41 additions & 7 deletions app/components/errors/utils.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,70 @@
import { z } from "zod";
import { isRouteError } from "~/utils/http";

/**
* Base schema for additional error data.
* Contains common fields used across different error types.
*/
const baseAdditionalDataSchema = z.object({
/** Unique identifier for the error instance */
id: z.string(),
/** Optional URL to redirect the user to after error handling */
redirectTo: z.string().optional(),
});

/**
* Schema defining organization structure used in error data
*/
const organizationSchema = z.object({
organization: z.object({
/** Organization's unique identifier */
id: z.string(),
/** Organization's display name */
name: z.string(),
}),
});

/**
* Schema for 404 error additional data.
* Uses a discriminated union to handle different model types with specific requirements.
*/
export const error404AdditionalDataSchema = z.discriminatedUnion("model", [
/* For common and general use case */
baseAdditionalDataSchema.extend({
/** Type of resource that wasn't found */
model: z.enum(["asset", "kit", "location", "booking", "customField"]),
/** Organization context where the resource wasn't found */
organization: organizationSchema,
}),
/* A team member (user) can be in multiple organization's of user so we do this. */
baseAdditionalDataSchema.extend({
/** Specific case for team member not found errors */
model: z.literal("teamMember"),
/** List of organizations the team member could belong to */
organizations: organizationSchema.array(),
}),
]);

/**
* Type definition for the 404 error additional data structure
*/
export type Error404AdditionalData = z.infer<
typeof error404AdditionalDataSchema
>;

export function parse404ErrorData(response: unknown):
/**
* Parses and validates the structure of a 404 error response.
*
* @param response - The unknown response to be parsed
* @returns An object indicating whether it's a valid 404 error and its additional data
* If it's not a valid 404 error or parsing fails, returns {isError404: false, additionalData: null}
* If it's a valid 404 error, returns {isError404: true, additionalData: Error404AdditionalData}
*/
export function parse404ErrorData(
response: unknown
):
| { isError404: false; additionalData: null }
| {
isError404: true;
additionalData: Error404AdditionalData;
} {
| { isError404: true; additionalData: Error404AdditionalData } {
if (!isRouteError(response)) {
return { isError404: false, additionalData: null };
}
Expand All @@ -51,12 +80,17 @@ export function parse404ErrorData(response: unknown):
return { isError404: true, additionalData: parsedDataResponse.data };
}

/**
* Converts a model enum value to a human-readable label.
*
* @param model - The model type from Error404AdditionalData
* @returns A string representing the human-readable label for the model
*/
export function getModelLabelForEnumValue(
model: Error404AdditionalData["model"]
) {
): string {
if (model === "customField") {
return "Custom field";
}

return model;
}
8 changes: 6 additions & 2 deletions app/components/icons/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ import type { IconType } from "../shared/icons-map";
import iconsMap from "../shared/icons-map";

export interface IconProps {
className?: string;
icon: IconType;
disableWrap?: true;
size?: React.ComponentProps<typeof IconHug>["size"];
}
const Icon = React.forwardRef<HTMLElement, IconProps>(function Icon(
{ icon, disableWrap }: IconProps,
{ className, icon, disableWrap, size = "sm" }: IconProps,
_ref
) {
return (
icon &&
(disableWrap ? (
<div>{iconsMap[icon]}</div>
) : (
<IconHug size="sm">{iconsMap[icon]}</IconHug>
<IconHug className={className} size={size}>
{iconsMap[icon]}
</IconHug>
))
);
});
Expand Down
4 changes: 3 additions & 1 deletion app/components/icons/iconHug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { tw } from "~/utils/tw";

interface Props {
/** Size of the hug. Defualt is sm */
size: "sm" | "md" | "lg" | "xl" | "2xl";
size: "xs" | "sm" | "md" | "lg" | "xl" | "2xl";

children: JSX.Element | JSX.Element[];

Expand All @@ -16,6 +16,8 @@ interface Props {
const sizeClasses: {
[key in Props["size"]]: string;
} = {
/** 16 */
xs: "w-4 h-4",
/** 32px */
sm: "w-5 h-5",
/** 40px */
Expand Down
36 changes: 19 additions & 17 deletions app/components/icons/library.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ export function ItemsIcon(props: SVGProps<SVGSVGElement>) {
export function SettingsIcon(props: SVGProps<SVGSVGElement>) {
return (
<svg
width="100%"
height="100%"
width="20"
DonKoko marked this conversation as resolved.
Show resolved Hide resolved
height="20"
viewBox="0 0 22 22"
fill="none"
xmlns="http://www.w3.org/2000/svg"
Expand Down Expand Up @@ -436,8 +436,9 @@ export function XIcon(props: SVGProps<SVGSVGElement>) {

export const AssetsIcon = (props: SVGProps<SVGSVGElement>) => (
<svg
width={20}
height={22}
width="20"
height="20"
viewBox="0 0 20 20"
fill="none"
xmlns="http://www.w3.org/2000/svg"
{...props}
Expand Down Expand Up @@ -854,8 +855,9 @@ export const WriteIcon = (props: SVGProps<SVGSVGElement>) => (
export const TagsIcon = (props: SVGProps<SVGSVGElement>) => (
<svg
xmlns="http://www.w3.org/2000/svg"
width={20}
height={23}
width="20"
height="20"
viewBox="0 0 20 20"
fill="none"
{...props}
>
Expand Down Expand Up @@ -923,9 +925,9 @@ export const RemoveTagsIcon = (props: SVGProps<SVGSVGElement>) => (

export const LocationMarkerIcon = (props: SVGProps<SVGSVGElement>) => (
<svg
width="18"
height="22"
viewBox="0 0 18 22"
width="20"
height="20"
viewBox="0 0 20 20"
fill="none"
xmlns="http://www.w3.org/2000/svg"
{...props}
Expand Down Expand Up @@ -1454,9 +1456,9 @@ export const CalendarIcon = (props: SVGProps<SVGSVGElement>) => (
export const BookingsIcon = (props: SVGProps<SVGSVGElement>) => (
<svg
xmlns="http://www.w3.org/2000/svg"
width="100%"
height="100%"
viewBox="0 0 20 22"
width="20"
height="20"
viewBox="0 0 20 20"
fill="none"
{...props}
>
Expand Down Expand Up @@ -1491,8 +1493,8 @@ export const CustomFiedIcon = (props: SVGProps<SVGSVGElement>) => (

export const KitIcon = (props: SVGProps<SVGSVGElement>) => (
<svg
width="100%"
height="100%"
width="18"
height="20"
viewBox="0 0 22 20"
fill="none"
xmlns="http://www.w3.org/2000/svg"
Expand Down Expand Up @@ -1572,9 +1574,9 @@ export const AssetLabel = (props: SVGProps<SVGSVGElement>) => (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
width="100%"
height="100%"
viewBox="0 0 24 24"
width="18"
height="20"
viewBox="0 0 22 20"
{...props}
>
<path
Expand Down
44 changes: 44 additions & 0 deletions app/components/layout/sidebar/app-sidebar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { ShelfSidebarLogo } from "~/components/marketing/logos";
import { useSidebarNavItems } from "~/hooks/use-sidebar-nav-items";
import { SidebarNoticeCard } from "./notice-card";
import OrganizationSelector from "./organization-selector";
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarHeader,
SidebarRail,
useSidebar,
} from "./sidebar";
import SidebarNav from "./sidebar-nav";
import SidebarUserMenu from "./sidebar-user-menu";

type AppSidebarProps = React.ComponentProps<typeof Sidebar>;

export default function AppSidebar(props: AppSidebarProps) {
const { state } = useSidebar();
const { topMenuItems, bottomMenuItems } = useSidebarNavItems();

return (
<Sidebar collapsible="icon" {...props}>
<SidebarHeader className={state === "collapsed" ? "px-0" : ""}>
<div className="my-2 flex items-center">
<ShelfSidebarLogo minimized={state === "collapsed"} />
</div>

<OrganizationSelector />
</SidebarHeader>

<SidebarContent>
<SidebarNav items={topMenuItems} />
</SidebarContent>

<SidebarFooter>
<SidebarNoticeCard />
<SidebarNav className="p-0" items={bottomMenuItems} />
<SidebarUserMenu />
</SidebarFooter>
<SidebarRail />
</Sidebar>
);
}
31 changes: 0 additions & 31 deletions app/components/layout/sidebar/atoms.ts

This file was deleted.

Loading
Loading