mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-27 19:34:38 +00:00
feat(sandbox): default Network Sandbox to off and add settings toggle switch (#304)
This commit is contained in:
@@ -5,7 +5,8 @@ import { ScrollArea } from '@/ui/components/ui/scroll-area'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/ui/components/ui/card'
|
||||
import { Input } from '@/ui/components/ui/input'
|
||||
import { Button } from '@/ui/components/ui/button'
|
||||
import { Loader2, Plus, X, Globe, Check, Trash2, ShieldAlert } from 'lucide-react'
|
||||
import { Switch } from '@/ui/components/ui/switch'
|
||||
import { Loader2, Plus, X, Globe, Check, Trash2, ShieldAlert, Info } from 'lucide-react'
|
||||
import { toast } from 'sonner'
|
||||
import { m } from '@/ui/paraglide/messages.js'
|
||||
|
||||
@@ -25,7 +26,11 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
})
|
||||
|
||||
const { mutate: updateSandbox, isPending: isUpdating } = useMutation({
|
||||
mutationFn: async (params: { allowedDomains: string[]; pendingDomains: string[] }) => {
|
||||
mutationFn: async (params: {
|
||||
networkSandboxEnabled?: boolean
|
||||
allowedDomains?: string[]
|
||||
pendingDomains?: string[]
|
||||
}) => {
|
||||
const res = await client.api.teams[':teamId'].sandbox.$put({
|
||||
param: { teamId },
|
||||
json: params,
|
||||
@@ -42,6 +47,12 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
},
|
||||
})
|
||||
|
||||
const handleToggleNetworkSandbox = (enabled: boolean) => {
|
||||
updateSandbox({
|
||||
networkSandboxEnabled: enabled,
|
||||
})
|
||||
}
|
||||
|
||||
const handleAddDomain = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!newDomain.trim()) return
|
||||
@@ -80,6 +91,8 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
)
|
||||
}
|
||||
|
||||
const isNetworkSandboxEnabled = !!sandbox?.networkSandboxEnabled
|
||||
|
||||
return (
|
||||
<ScrollArea className="h-full">
|
||||
<div className="space-y-6 pr-4 pb-8">
|
||||
@@ -92,14 +105,42 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
<CardDescription>{m.network_sandbox_description()}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{/* Toggle Switch */}
|
||||
<div className="flex items-center justify-between p-4 mb-6 rounded-lg border border-border bg-muted/30">
|
||||
<div className="space-y-0.5 pr-4">
|
||||
<label
|
||||
htmlFor="network-sandbox-switch"
|
||||
className="text-sm font-medium text-foreground cursor-pointer"
|
||||
>
|
||||
{m.enable_network_sandbox()}
|
||||
</label>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{m.network_sandbox_enabled_description()}
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
id="network-sandbox-switch"
|
||||
checked={isNetworkSandboxEnabled}
|
||||
onCheckedChange={handleToggleNetworkSandbox}
|
||||
disabled={isUpdating}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{!isNetworkSandboxEnabled && (
|
||||
<div className="flex items-start gap-2.5 p-3.5 mb-6 rounded-lg bg-amber-500/10 border border-amber-500/20 text-amber-700 dark:text-amber-300 text-sm">
|
||||
<Info className="w-4 h-4 mt-0.5 shrink-0" />
|
||||
<span>{m.network_sandbox_disabled_notice()}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<form onSubmit={handleAddDomain} className="flex gap-2 mb-6">
|
||||
<Input
|
||||
placeholder="e.g. api.openai.com"
|
||||
value={newDomain}
|
||||
onChange={(e) => setNewDomain(e.target.value)}
|
||||
disabled={isUpdating}
|
||||
disabled={isUpdating || !isNetworkSandboxEnabled}
|
||||
/>
|
||||
<Button type="submit" disabled={isUpdating}>
|
||||
<Button type="submit" disabled={isUpdating || !isNetworkSandboxEnabled}>
|
||||
{isUpdating ? (
|
||||
<Loader2 className="w-4 h-4 animate-spin" />
|
||||
) : (
|
||||
@@ -114,7 +155,7 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
{m.allowed_domains()}
|
||||
</h4>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{sandbox?.allowedDomains.map((domain) => (
|
||||
{sandbox?.allowedDomains.map((domain: string) => (
|
||||
<div
|
||||
key={domain}
|
||||
className="flex items-center gap-1 px-3 py-1.5 bg-muted rounded-full text-sm border border-border transition-all hover:border-muted-foreground/50"
|
||||
@@ -122,8 +163,8 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
<span className="font-medium text-foreground">{domain}</span>
|
||||
<button
|
||||
onClick={() => handleRemoveDomain(domain)}
|
||||
className="ml-1 text-muted-foreground hover:text-destructive transition-colors"
|
||||
disabled={isUpdating}
|
||||
className="ml-1 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
disabled={isUpdating || !isNetworkSandboxEnabled}
|
||||
>
|
||||
<X className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
@@ -152,7 +193,7 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
<div className="space-y-3">
|
||||
{sandbox?.pendingDomains && sandbox.pendingDomains.length > 0 ? (
|
||||
<div className="divide-y divide-border">
|
||||
{sandbox.pendingDomains.map((domain) => (
|
||||
{sandbox.pendingDomains.map((domain: string) => (
|
||||
<div
|
||||
key={domain}
|
||||
className="flex items-center justify-between py-2.5 first:pt-0 last:pb-0"
|
||||
@@ -166,7 +207,7 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
variant="outline"
|
||||
className="h-8 border-emerald-500/20 text-emerald-600 hover:bg-emerald-500/10 hover:text-emerald-600 dark:text-emerald-400 dark:hover:bg-emerald-500/20"
|
||||
onClick={() => handleApproveDomain(domain)}
|
||||
disabled={isUpdating}
|
||||
disabled={isUpdating || !isNetworkSandboxEnabled}
|
||||
>
|
||||
<Check className="w-4 h-4 mr-1.5" />
|
||||
{m.approve()}
|
||||
@@ -176,7 +217,7 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
variant="outline"
|
||||
className="h-8 border-destructive/20 text-destructive hover:bg-destructive/10"
|
||||
onClick={() => handleDeletePendingDomain(domain)}
|
||||
disabled={isUpdating}
|
||||
disabled={isUpdating || !isNetworkSandboxEnabled}
|
||||
>
|
||||
<Trash2 className="w-4 h-4 mr-1.5" />
|
||||
{m.delete()}
|
||||
|
||||
Reference in New Issue
Block a user