Skip to content

Commit 0703348

Browse files
committed
add sprints store and revalidation on add, delete, edit sprint
1 parent 29be079 commit 0703348

7 files changed

Lines changed: 299 additions & 234 deletions

File tree

‎apps/codebility/app/home/kanban/[projectId]/_components/SprintAddModal.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from "@/components/ui/dialog";
1313
import { useModal } from "@/hooks/use-modal-sprints";
1414
import { objectToFormData } from "@/lib/form-data";
15+
import { useSprintStore } from "@/store/sprints-store";
1516
import { zodResolver } from "@hookform/resolvers/zod";
1617
import { isBefore, isEqual } from "date-fns";
1718
import { useForm } from "react-hook-form";
@@ -53,6 +54,7 @@ const SprintAddModal = () => {
5354
const isModalOpen = isOpen && type === "sprintAddModal";
5455

5556
const [isLoading, setIsLoading] = useState(false);
57+
const { fetchSprintsData } = useSprintStore();
5658

5759
const form = useForm<FormValues>({
5860
resolver: zodResolver(formSchema),
@@ -92,6 +94,8 @@ const SprintAddModal = () => {
9294
toast.error("Something went wrong!");
9395
} finally {
9496
setIsLoading(false);
97+
//revalidate sprints
98+
fetchSprintsData();
9599
}
96100
};
97101

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"use server"
2+
3+
import { createClientServerComponent } from "@/utils/supabase/server";
4+
5+
export const getSprintsData = async (projectId: String) => {
6+
try {
7+
const supabase = await createClientServerComponent();
8+
9+
// Fetch project + sprints
10+
const { data, error } = await supabase
11+
.from("projects")
12+
.select(
13+
`
14+
id,
15+
name,
16+
kanban_sprints!kanban_sprints_project_id_fkey (
17+
id,
18+
name,
19+
start_at,
20+
end_at,
21+
project_id,
22+
board_id,
23+
kanban_board:kanban_boards!kanban_sprints_board_id_fkey (
24+
id,
25+
name
26+
)
27+
)
28+
`,
29+
)
30+
.eq("id", projectId)
31+
.single();
32+
33+
return data;
34+
} catch (error) {
35+
console.error(error);
36+
throw error;
37+
}
38+
};

‎apps/codebility/app/home/kanban/[projectId]/actions.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ export async function createNewSprint(formData: FormData) {
6969
return { success: false, error: sprint.error.message };
7070
}
7171

72-
// Revalidate the KanbanSprintPage to refresh the sprints list
73-
revalidatePath(`/kanban/${projectId}`);
74-
7572
return {
7673
success: true,
7774
data: {

0 commit comments

Comments
 (0)