Skip to content

Commit

Permalink
feat: hide create template button for unauthorized roles (#607)
Browse files Browse the repository at this point in the history
  • Loading branch information
hughcrt authored Oct 11, 2024
1 parent bd4e8b3 commit 4551811
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions packages/frontend/pages/prompts/[[...id]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -479,22 +479,35 @@ function Playground() {
<Stack style={{ zIndex: 0 }}>
{template && templateVersion && (
<Group>
<Button
leftSection={<IconDeviceFloppy size={18} />}
size="xs"
loading={loading}
data-testid="save-template"
disabled={loading || (template?.id && !hasChanges)}
variant="outline"
// rightSection={
// <HotkeysInfo hot="S" size="sm" style={{ marginTop: -4 }} />
// }
onClick={saveTemplate}
>
{templateVersion?.id
? "Save changes"
: "Save as new template"}
</Button>
{!templateVersion?.id &&
hasAccess(user.role, "prompts", "create") && (
<Button
leftSection={<IconDeviceFloppy size={18} />}
size="xs"
loading={loading}
data-testid="save-template"
disabled={loading || (template?.id && !hasChanges)}
variant="outline"
onClick={saveTemplate}
>
Save as new template
</Button>
)}

{templateVersion?.id &&
hasAccess(user.role, "prompts", "create_draft") && (
<Button
leftSection={<IconDeviceFloppy size={18} />}
size="xs"
loading={loading}
data-testid="save-template"
disabled={loading || (template?.id && !hasChanges)}
variant="outline"
onClick={saveTemplate}
>
Save changes
</Button>
)}

{hasAccess(user.role, "prompts", "update") &&
templateVersion?.id && (
Expand Down

0 comments on commit 4551811

Please sign in to comment.