mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-13 07:25:17 +00:00
Merge pull request #5118 from andwati/fix/tag-assignment-on-project-create
fix: assign tags created from the project dialog
This commit is contained in:
@@ -53,9 +53,14 @@ type Tag = z.infer<typeof TagSchema>;
|
|||||||
|
|
||||||
interface HandleTagProps {
|
interface HandleTagProps {
|
||||||
tagId?: string;
|
tagId?: string;
|
||||||
|
/**
|
||||||
|
* Called with the new tag's id after it is created, so callers embedding
|
||||||
|
* this dialog (e.g. the tag selector) can select the tag right away.
|
||||||
|
*/
|
||||||
|
onCreated?: (tagId: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const HandleTag = ({ tagId }: HandleTagProps) => {
|
export const HandleTag = ({ tagId, onCreated }: HandleTagProps) => {
|
||||||
const utils = api.useUtils();
|
const utils = api.useUtils();
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const colorInputRef = useRef<HTMLInputElement>(null);
|
const colorInputRef = useRef<HTMLInputElement>(null);
|
||||||
@@ -101,8 +106,11 @@ export const HandleTag = ({ tagId }: HandleTagProps) => {
|
|||||||
color: data.color,
|
color: data.color,
|
||||||
tagId: tagId || "",
|
tagId: tagId || "",
|
||||||
})
|
})
|
||||||
.then(async () => {
|
.then(async (result) => {
|
||||||
await utils.tag.all.invalidate();
|
await utils.tag.all.invalidate();
|
||||||
|
if (!tagId && result?.tagId) {
|
||||||
|
onCreated?.(result.tagId);
|
||||||
|
}
|
||||||
toast.success(tagId ? "Tag Updated" : "Tag Created");
|
toast.success(tagId ? "Tag Updated" : "Tag Created");
|
||||||
setIsOpen(false);
|
setIsOpen(false);
|
||||||
form.reset();
|
form.reset();
|
||||||
@@ -139,9 +147,18 @@ export const HandleTag = ({ tagId }: HandleTagProps) => {
|
|||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
{isError && <AlertBlock type="error">{error?.message}</AlertBlock>}
|
{isError && <AlertBlock type="error">{error?.message}</AlertBlock>}
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
|
{/*
|
||||||
|
* This dialog can be rendered inside another form (e.g. the tag
|
||||||
|
* selector in the project dialog). React propagates events through the
|
||||||
|
* React tree, not the DOM tree, so without stopPropagation submitting
|
||||||
|
* this form would also submit the outer one.
|
||||||
|
*/}
|
||||||
<form
|
<form
|
||||||
id="hook-form-tag"
|
id="hook-form-tag"
|
||||||
onSubmit={form.handleSubmit(onSubmit)}
|
onSubmit={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
form.handleSubmit(onSubmit)(e);
|
||||||
|
}}
|
||||||
className="grid w-full gap-4"
|
className="grid w-full gap-4"
|
||||||
>
|
>
|
||||||
<FormField
|
<FormField
|
||||||
|
|||||||
@@ -147,7 +147,13 @@ export function TagSelector({
|
|||||||
})}
|
})}
|
||||||
</CommandGroup>
|
</CommandGroup>
|
||||||
<div className="flex items-center justify-center p-2 border-t">
|
<div className="flex items-center justify-center p-2 border-t">
|
||||||
<HandleTag />
|
<HandleTag
|
||||||
|
onCreated={(tagId) => {
|
||||||
|
if (!selectedTags.includes(tagId)) {
|
||||||
|
onTagsChange([...selectedTags, tagId]);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</CommandList>
|
</CommandList>
|
||||||
</Command>
|
</Command>
|
||||||
|
|||||||
Reference in New Issue
Block a user