-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
547 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
vibraniumdome-app/src/app/users/components/create-policy-dialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
"use client" | ||
|
||
import { Button } from "~/app/components/ui/button" | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogDescription, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from "~/app/components/ui/dialog" | ||
import { Input } from "~/app/components/ui/input" | ||
import { Label } from "~/app/components/ui/label" | ||
import { Textarea } from "~/app/components/ui/textarea" | ||
import * as React from "react" | ||
import { useRouter } from "next/navigation"; | ||
import { api } from "~/trpc/react"; | ||
|
||
export type Policy = { | ||
id: string | ||
name: string | ||
llmAppName: number | ||
content: string | ||
createdAt: string | ||
} | ||
|
||
export function CreatePolicyDialog() { | ||
const [open, setOpen] = React.useState(false); | ||
const router = useRouter(); | ||
|
||
const [policyName, setPolicyName] = React.useState(''); | ||
const [llmAppName, setLlmAppName] = React.useState(''); | ||
const textareaRef = React.useRef(null); | ||
|
||
const createPolicy = api.policy.create.useMutation({ | ||
onSuccess: () => { | ||
router.refresh(); | ||
}, | ||
}); | ||
|
||
const saveChanges = async () => { | ||
setOpen(false); | ||
await createPolicy.mutate({name: policyName, | ||
llmAppName: llmAppName, | ||
// @ts-ignore | ||
content: textareaRef.current?.value, | ||
}) | ||
}; | ||
|
||
const defaultPolicy = api.policy.getDefaultPolicy.useQuery().data; | ||
|
||
return ( | ||
<Dialog open={open} onOpenChange={setOpen}> | ||
<DialogTrigger asChild> | ||
<Button>Create Policy</Button> | ||
</DialogTrigger> | ||
|
||
<DialogContent className="sm:max-w-[825px]"> | ||
<DialogHeader> | ||
<DialogTitle>Create policy</DialogTitle> | ||
<DialogDescription> | ||
Make policy changes. Click save when you're done. | ||
</DialogDescription> | ||
</DialogHeader> | ||
<div className="grid gap-4 py-4"> | ||
<div className="grid grid-cols-4 items-center gap-4"> | ||
<Label htmlFor="policyName" className="text-right"> | ||
Policy Name | ||
</Label> | ||
<Input | ||
id="name" | ||
defaultValue="" | ||
className="col-span-3" | ||
onChange={(e) => setPolicyName(e.target.value)} | ||
/> | ||
</div> | ||
<div className="grid grid-cols-4 items-center gap-4"> | ||
<Label htmlFor="llmAppName" className="text-right"> | ||
LLM App Name | ||
</Label> | ||
<Input | ||
id="llmAppName" | ||
defaultValue="" | ||
className="col-span-3" | ||
onChange={(e) => setLlmAppName(e.target.value)} | ||
/> | ||
</div> | ||
<div className="grid grid-cols-4 items-center gap-4"> | ||
<Label htmlFor="llmAppName" className="text-right"> | ||
Policy Content | ||
</Label> | ||
<Textarea className="col-span-3" | ||
ref={textareaRef} | ||
defaultValue={JSON.stringify(defaultPolicy?.content, null, 4)} | ||
placeholder="" | ||
/> | ||
</div> | ||
</div> | ||
<DialogFooter> | ||
<Button type="submit" onClick={saveChanges}>Save changes</Button> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
) | ||
|
||
} |
Oops, something went wrong.