From 0e49ccef8e6d5346bd45d943fdcac0ecd89820b0 Mon Sep 17 00:00:00 2001 From: Aarnav Tale Date: Sat, 5 Apr 2025 18:54:30 -0400 Subject: [PATCH] chore: update notice instead of using a custom one on acls --- app/components/Notice.tsx | 39 ++++++++++++++++++++---- app/routes/acls/components/error.tsx | 45 ---------------------------- app/routes/acls/overview.tsx | 18 ++++++----- 3 files changed, 45 insertions(+), 57 deletions(-) delete mode 100644 app/routes/acls/components/error.tsx diff --git a/app/components/Notice.tsx b/app/components/Notice.tsx index 18cecde..9200019 100644 --- a/app/components/Notice.tsx +++ b/app/components/Notice.tsx @@ -1,16 +1,45 @@ -import { CircleSlash2 } from 'lucide-react'; +import { + CircleAlert, + CircleSlash2, + LucideProps, + TriangleAlert, +} from 'lucide-react'; import React from 'react'; import Card from '~/components/Card'; export interface NoticeProps { children: React.ReactNode; + title?: string; + variant?: 'default' | 'error' | 'warning'; + icon?: React.ReactElement; } -export default function Notice({ children }: NoticeProps) { +export default function Notice({ + children, + title, + variant, + icon, +}: NoticeProps) { return ( - - - {children} + +
+ {title ? ( + {title} + ) : undefined} + {!variant && icon ? icon : iconForVariant(variant)} +
+ {children}
); } + +function iconForVariant(variant?: 'default' | 'error' | 'warning') { + switch (variant) { + case 'error': + return ; + case 'warning': + return ; + default: + return ; + } +} diff --git a/app/routes/acls/components/error.tsx b/app/routes/acls/components/error.tsx deleted file mode 100644 index 82e893f..0000000 --- a/app/routes/acls/components/error.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import { AlertIcon } from '@primer/octicons-react'; -import React from 'react'; -import Card from '~/components/Card'; - -interface NoticeViewProps { - title: string; - children: React.ReactNode; -} - -export function NoticeView({ children, title }: NoticeViewProps) { - return ( - -
- {title} - -
- {children} -
- ); -} - -interface ErrorViewProps { - children: string; -} - -export function ErrorView({ children }: ErrorViewProps) { - const [title, ...rest] = children.split(':'); - const formattedMessage = rest.length > 0 ? rest.join(':').trim() : children; - - return ( - -
- - {title.trim() ?? 'Error'} - - -
- - Could not apply changes to the ACL policy: -
- {formattedMessage} -
-
- ); -} diff --git a/app/routes/acls/overview.tsx b/app/routes/acls/overview.tsx index 91d8039..01611eb 100644 --- a/app/routes/acls/overview.tsx +++ b/app/routes/acls/overview.tsx @@ -17,7 +17,6 @@ import toast from '~/utils/toast'; import { aclAction } from './acl-action'; import { aclLoader } from './acl-loader'; import { Differ, Editor } from './components/cm.client'; -import { ErrorView, NoticeView } from './components/error'; export async function loader(request: LoaderFunctionArgs) { return aclLoader(request); @@ -57,19 +56,19 @@ export default function Page() { return (
{!access ? ( - + You do not have the necessary permissions to edit the Access Control List policy. Please contact your administrator to request access or to make changes to the ACL policy. - + ) : !writable ? ( - + The ACL policy mode is most likely set to file in your Headscale configuration. This means that the ACL file cannot be edited through the web interface. In order to resolve this, you'll need to set acl.mode to database in your Headscale configuration. - + ) : undefined}

Access Control List (ACL)

@@ -91,7 +90,13 @@ export default function Page() { .

{fetcher.data?.error !== undefined ? ( - {fetcher.data.error} + + {fetcher.data.error.split(':').slice(1).join(': ') ?? + 'An unknown error occurred while trying to update the ACL policy.'} + ) : undefined} { const formData = new FormData(); - console.log(codePolicy); formData.append('policy', codePolicy); fetcher.submit(formData, { method: 'PATCH' }); }}