Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Nov 19, 2024
1 parent 61c434a commit e020e47
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
4 changes: 2 additions & 2 deletions apps/dashboard/src/actions/project/create-project-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export const createProjectAction = authActionClient
await supabase.from("tracker_project_tags").insert(
tags.map((tag) => ({
tag_id: tag.id,
tracker_project_id: data?.id ?? "",
team_id: user.team_id ?? "",
tracker_project_id: data?.id,
team_id: user.team_id!,
})),
);
}
Expand Down
2 changes: 0 additions & 2 deletions apps/dashboard/src/actions/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ export const createProjectSchema = z.object({
.array(
z.object({
id: z.string().uuid(),
label: z.string(),
value: z.string(),
}),
)
Expand All @@ -367,7 +366,6 @@ export const updateProjectSchema = z.object({
.array(
z.object({
id: z.string().uuid(),
label: z.string(),
value: z.string(),
}),
)
Expand Down
19 changes: 13 additions & 6 deletions apps/dashboard/src/components/forms/tracker-project-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,19 @@ export function TrackerProjectForm({
});
}}
// Only for create projects
onChange={(tags) => {
onCreate={(tag) => {
if (!isEdit) {
form.setValue("tags", tags, {
shouldDirty: true,
shouldValidate: true,
});
form.setValue(
"tags",
[
...(form.getValues("tags") ?? []),
{ id: tag.id, value: tag.name },
],
{
shouldDirty: true,
shouldValidate: true,
},
);
}
}}
// Only for edit projects
Expand Down Expand Up @@ -295,7 +302,7 @@ export function TrackerProjectForm({
<div className="fixed bottom-8 w-full sm:max-w-[455px] right-8">
<Button
className="w-full"
disabled={isSaving || form.formState.isValid}
disabled={isSaving || !form.formState.isValid}
>
{isSaving ? <Loader2 className="h-4 w-4 animate-spin" /> : "Save"}
</Button>
Expand Down
13 changes: 11 additions & 2 deletions apps/dashboard/src/components/select-tags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,25 @@ type Props = {
onSelect?: (tag: Option) => void;
onRemove?: (tag: Option & { id: string }) => void;
onChange?: (tags: Option[]) => void;
onCreate?: (tag: Option) => void;
};

export function SelectTags({ tags, onSelect, onRemove, onChange }: Props) {
export function SelectTags({
tags,
onSelect,
onRemove,
onChange,
onCreate,
}: Props) {
const supabase = createClient();

const [data, setData] = useState<Option[]>(tags ?? []);
const [selected, setSelected] = useState<Option[]>(tags ?? []);

const createTag = useAction(createTagAction, {
onSuccess: ({ data }) => {
onSelect(data);
onSelect?.(data);
onCreate?.(data);
},
});

Expand Down

0 comments on commit e020e47

Please sign in to comment.