Skip to content

Commit 41745fe

Browse files
committed
Admin data stores editing
1 parent 021e088 commit 41745fe

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

apps/webapp/app/routes/admin.data-stores.tsx

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,10 @@ export default function AdminDataStoresRoute() {
235235
</span>
236236
</TableCell>
237237
<TableCell isSticky>
238-
<DeleteButton name={ds.key} />
238+
<div className="flex items-center gap-1">
239+
<EditButton name={ds.key} organizationIds={ds.organizationIds} />
240+
<DeleteButton name={ds.key} />
241+
</div>
239242
</TableCell>
240243
</TableRow>
241244
))
@@ -290,6 +293,70 @@ function DeleteButton({ name }: { name: string }) {
290293
);
291294
}
292295

296+
// ---------------------------------------------------------------------------
297+
// Edit button with dialog
298+
// ---------------------------------------------------------------------------
299+
300+
function EditButton({ name, organizationIds }: { name: string; organizationIds: string[] }) {
301+
const [open, setOpen] = useState(false);
302+
const fetcher = useFetcher<{ success?: boolean; error?: string }>();
303+
const isSubmitting = fetcher.state !== "idle";
304+
305+
if (fetcher.data?.success && open) {
306+
setOpen(false);
307+
}
308+
309+
return (
310+
<>
311+
<Button variant="secondary/small" onClick={() => setOpen(true)}>
312+
Edit
313+
</Button>
314+
<Dialog open={open} onOpenChange={setOpen}>
315+
<DialogContent className="sm:max-w-lg">
316+
<DialogHeader>
317+
<DialogTitle>Edit data store</DialogTitle>
318+
</DialogHeader>
319+
320+
<fetcher.Form method="post" className="space-y-4 pt-2">
321+
<input type="hidden" name="_action" value="update" />
322+
<input type="hidden" name="key" value={name} />
323+
324+
<div className="space-y-1.5">
325+
<label className="text-xs font-medium text-text-dimmed">Key</label>
326+
<Input name="_key_display" value={name} readOnly variant="medium" className="font-mono opacity-60" />
327+
</div>
328+
329+
<div className="space-y-1.5">
330+
<label className="text-xs font-medium text-text-dimmed">
331+
Organization IDs <span className="text-rose-400">*</span>
332+
</label>
333+
<Input
334+
name="organizationIds"
335+
defaultValue={organizationIds.join(", ")}
336+
placeholder="clxxxxx, clyyyyy, clzzzzz"
337+
variant="medium"
338+
required
339+
/>
340+
<p className="text-[11px] text-text-dimmed">Comma-separated organization IDs.</p>
341+
</div>
342+
343+
{fetcher.data?.error && <p className="text-xs text-rose-400">{fetcher.data.error}</p>}
344+
345+
<DialogFooter>
346+
<Button variant="tertiary/small" type="button" onClick={() => setOpen(false)} disabled={isSubmitting}>
347+
Cancel
348+
</Button>
349+
<Button type="submit" variant="primary/small" disabled={isSubmitting}>
350+
{isSubmitting ? "Saving…" : "Save"}
351+
</Button>
352+
</DialogFooter>
353+
</fetcher.Form>
354+
</DialogContent>
355+
</Dialog>
356+
</>
357+
);
358+
}
359+
293360
// ---------------------------------------------------------------------------
294361
// Add data store dialog
295362
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)