Skip to content

Commit

Permalink
Put UserCreateSheet on it's own route
Browse files Browse the repository at this point in the history
So `useBeforeLeave` works!
  • Loading branch information
oscartbeaumont committed Aug 18, 2024
1 parent 64e4db3 commit b7163a7
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 64 deletions.
2 changes: 1 addition & 1 deletion apps/configure/src/components/search/TableContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function TableContent(
const d = rawData();
if (!d) return [];

return d.sort((a, b) => a.data.name.localeCompare(b.data.name));
return [...d].sort((a, b) => a.data.name.localeCompare(b.data.name));
});

const virtualizer = createWindowVirtualizer({
Expand Down
2 changes: 1 addition & 1 deletion apps/configure/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const routes = [
component: lazy(() => import("./routes/(dash)/(overview)")),
},
{
path: "/users",
path: ["/users", "/users/new"],
component: lazy(() => import("./routes/(dash)/users/(users)")),
},
{
Expand Down
33 changes: 26 additions & 7 deletions apps/configure/src/routes/(dash)/users/(users).tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from "@mattrax/ui/forms";
import { latestNoSuspense } from "@mattrax/ui/lib";
import { createConnectivitySignal } from "@solid-primitives/connectivity";
import { createAsync, useNavigate } from "@solidjs/router";
import { createAsync, useLocation, useNavigate } from "@solidjs/router";
import { Show, Suspense, createSignal } from "solid-js";
import { z } from "zod";
import { PageLayout, PageLayoutHeading } from "~/components/PageLayout";
Expand All @@ -35,6 +35,8 @@ import { createDbQuery } from "~/lib/query";
import { useSync } from "~/lib/sync";

export default function Page() {
const navigate = useNavigate();
const location = useLocation();
const ctx = createSearchPageContext([
{
type: "enum",
Expand All @@ -43,19 +45,36 @@ export default function Page() {
},
]);

const isSheetOpen = () => location.pathname.endsWith("/new");

return (
<PageLayout
class="max-w-7xl space-y-2"
heading={
<>
<PageLayoutHeading>Users</PageLayoutHeading>
<Sheet open={true}>
<SheetTrigger as={Button}>
<Sheet
open={isSheetOpen()}
onOpenChange={(isOpen) => {
if (!isOpen) navigate("..");
}}
>
<SheetTrigger
as={Button}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
navigate("new");
}}
>
Create
{/* // TODO: Add keyboard shortcut */}
{/* <Kbd class="ml-2">N</Kbd> */}
</SheetTrigger>
<CreateUserSheetContent />

<SheetContent>
<CreateUserSheet />
</SheetContent>
</Sheet>
</>
}
Expand All @@ -65,7 +84,7 @@ export default function Page() {
);
}

function CreateUserSheetContent() {
function CreateUserSheet() {
const navigate = useNavigate();
const sync = useSync();
const isOnline = createConnectivitySignal();
Expand Down Expand Up @@ -113,7 +132,7 @@ function CreateUserSheetContent() {
};

return (
<SheetContent>
<>
<SheetHeader>
<SheetTitle>Create user</SheetTitle>
<SheetDescription>
Expand Down Expand Up @@ -289,7 +308,7 @@ function CreateUserSheetContent() {
</Button>
</SheetFooter>
</Form>
</SheetContent>
</>
);
}

Expand Down
1 change: 0 additions & 1 deletion apps/web/src/api/trpc/routers/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ export const deviceRouter = createTRPCRouter({
const pols: Array<number> = [],
apps: Array<number> = [];

// biome-ignore lint/complexity/noForEach: <explanation>
input.assignments.forEach((a) => {
if (a.variant === "policy") pols.push(a.pk);
else apps.push(a.pk);
Expand Down
2 changes: 0 additions & 2 deletions apps/web/src/api/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export function getEmailDomain(email: string) {
}

export function omit<T, K extends string>(obj: T, keys: K[]): Omit<T, K> {
// biome-ignore lint/complexity/noForEach: <explanation>
// biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
keys.forEach((k) => ((obj as any)[k] = undefined));

return obj;
Expand Down
3 changes: 3 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
},
"correctness": {
"useJsxKeyInIterable": "off"
},
"complexity": {
"noForEach": "off"
}
}
},
Expand Down
1 change: 0 additions & 1 deletion packages/ui/src/chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ function showTooltip(context: ChartContext) {

let content = "";

// biome-ignore lint/complexity/noForEach:
model.title.forEach((title) => {
content += `<h3 class="font-semibold leading-none tracking-tight">${title}</h3>`;
});
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
type Controller,
ControllerProvider,
createController,
} from "./controller";
} from "./lib/controller";

const Dialog: Component<
Omit<DialogRootProps, "open"> &
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/dropdown-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
type Controller,
ControllerProvider,
createController,
} from "./controller";
} from "./lib/controller";

const DropdownMenu = <T extends ValidComponent = "div">(
props: Omit<
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/forms/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function Form<S>(
]);

useBeforeLeave((e) => {
if (!props.guardBeforeLeave) return;
if (props.guardBeforeLeave === false) return;
if (props.form.isDirty && !props.form.isSubmitting && !e.defaultPrevented) {
// preventDefault to block immediately and prompt user async
e.preventDefault();
Expand Down
2 changes: 0 additions & 2 deletions packages/ui/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export * from "./textarea";
export * from "./tooltip";
export * from "./timeline";
export * from "./dropdown-menu";
export * from "./controller";
export * from "./label";
export * from "./flat-tabs";
export * from "./badge";
Expand All @@ -29,7 +28,6 @@ export * from "./toggle";
export * from "./context-menu";
export * from "./number-input";
export * from "./description-list";
// export * from "./show";
export * from "./kbd";
export * from "./chart";
export * from "./progress";
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions packages/ui/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./contentEditable";
export * from "./solidv2";
export * from "./controller";
2 changes: 1 addition & 1 deletion packages/ui/src/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
type Controller,
ControllerProvider,
createController,
} from "./controller";
} from "./lib/controller";

const Popover: Component<
Omit<PopoverPrimitive.PopoverRootProps, "open"> &
Expand Down
45 changes: 0 additions & 45 deletions packages/ui/src/show.tsx

This file was deleted.

0 comments on commit b7163a7

Please sign in to comment.