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

feat: show logged in user context #1980

Merged
merged 2 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 31 additions & 0 deletions quadratic-client/src/dashboard/components/Empty.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { useRootRouteLoaderData } from '@/routes/_root';
import { Avatar } from '@/shared/components/Avatar';
import { TYPE } from '@/shared/constants/appConstants';
import { ROUTES } from '@/shared/constants/routes';
import { Button } from '@/shared/shadcn/ui/button';
import { cn } from '@/shared/shadcn/utils';
import { StopwatchIcon } from '@radix-ui/react-icons';
import { ReactNode } from 'react';
import { useSubmit } from 'react-router-dom';

export function Empty({
title,
Expand All @@ -10,14 +15,19 @@ export function Empty({
Icon,
severity,
className,
showLoggedInUser,
}: {
title: String;
description: ReactNode;
actions?: ReactNode;
Icon: typeof StopwatchIcon;
severity?: 'error';
className?: string;
showLoggedInUser?: boolean;
}) {
const { loggedInUser } = useRootRouteLoaderData();
const submit = useSubmit();

return (
<div className={cn(`max-w mx-auto my-10 max-w-md px-2 text-center`, className)}>
<div
Expand All @@ -30,6 +40,27 @@ export function Empty({
<div className={`text-sm text-muted-foreground`}>{description}</div>

{actions && <div className={`mt-8`}>{actions}</div>}
{showLoggedInUser && loggedInUser && (
<div className="mx-auto mt-12 max-w-96 border-t border-border pt-2">
<div className="mx-auto flex items-center gap-2 rounded-md pt-2 text-left text-sm">
<Avatar src={loggedInUser.picture} alt={`Avatar for ${loggedInUser.name}`} className="flex-shrink-0">
{loggedInUser.name}
</Avatar>
<div className="flex flex-col justify-start truncate">
{loggedInUser.name}
<span className="text-xs text-muted-foreground">{loggedInUser.email}</span>
</div>
<Button
variant="ghost"
size="sm"
className="ml-auto"
onClick={() => submit('', { method: 'POST', action: ROUTES.LOGOUT })}
>
Logout
</Button>
</div>
</div>
)}
</div>
);
}
3 changes: 3 additions & 0 deletions quadratic-client/src/routes/_dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ export const ErrorBoundary = () => {
description="Reach out to the team owner for permission to access this team."
Icon={InfoCircledIcon}
actions={actions}
showLoggedInUser
/>
);
if (error.status === 404 || error.status === 400)
Expand All @@ -290,6 +291,7 @@ export const ErrorBoundary = () => {
description="This team may have been deleted, moved, or made unavailable. Try reaching out to the team owner."
Icon={ExclamationTriangleIcon}
actions={actions}
showLoggedInUser
/>
);
}
Expand All @@ -307,6 +309,7 @@ export const ErrorBoundary = () => {
</Button>
}
severity="error"
showLoggedInUser
/>
);
};
11 changes: 10 additions & 1 deletion quadratic-client/src/routes/file.$uuid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,15 @@ export const ErrorBoundary = () => {
title = 'Failed to load file';
description = 'There was an error retrieving and loading this file.';
}
return <Empty title={title} description={description} Icon={ExclamationTriangleIcon} actions={actions} />;
return (
<Empty
title={title}
description={description}
Icon={ExclamationTriangleIcon}
actions={actions}
showLoggedInUser
/>
);
}

// If we reach here, it's an error we don't know how to handle.
Expand All @@ -172,6 +180,7 @@ export const ErrorBoundary = () => {
Icon={ExclamationTriangleIcon}
actions={actions}
severity="error"
showLoggedInUser
/>
);
};
Loading