Implement ST-401 activity status flows
This commit is contained in:
parent
4966d493cc
commit
d0739736aa
7 changed files with 228 additions and 5 deletions
|
|
@ -69,6 +69,11 @@ const planningStatusToasts: Record<string, StatusToast> = {
|
|||
title: "Activiteit gepland",
|
||||
message: "Je activiteit staat nu in je dagplanning van vandaag.",
|
||||
},
|
||||
"activity-status-saved": {
|
||||
variant: "success",
|
||||
title: "Activiteit bijgewerkt",
|
||||
message: "De status van je activiteit is opgeslagen.",
|
||||
},
|
||||
};
|
||||
|
||||
const planningErrorToasts: Record<string, StatusToast> = {
|
||||
|
|
@ -78,6 +83,16 @@ const planningErrorToasts: Record<string, StatusToast> = {
|
|||
message:
|
||||
"Controleer naam, categorie, duur, impact en prioriteit en probeer het opnieuw.",
|
||||
},
|
||||
"invalid-activity-status": {
|
||||
variant: "error",
|
||||
title: "Status niet opgeslagen",
|
||||
message: "De gekozen activiteit of status is ongeldig voor vandaag.",
|
||||
},
|
||||
"activity-status-failed": {
|
||||
variant: "error",
|
||||
title: "Status niet opgeslagen",
|
||||
message: "De activiteitstatus kon niet worden bijgewerkt. Probeer het opnieuw.",
|
||||
},
|
||||
};
|
||||
|
||||
export function getDashboardStatusToast(status: string | null): StatusToast | null {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import type {
|
|||
ActivitiesForDateStatus,
|
||||
ActivityStatus,
|
||||
SkipReason,
|
||||
UpdateActivityStatusSubmission,
|
||||
} from "@/lib/planning/types";
|
||||
import { ensureProfileBundleForCurrentUser } from "@/lib/profile/service";
|
||||
import { createClient } from "@/lib/supabase/server";
|
||||
|
|
@ -303,3 +304,43 @@ export async function createActivityForTodayForCurrentUser(
|
|||
|
||||
return mapActivityRow(data);
|
||||
}
|
||||
|
||||
export async function updateActivityStatusForTodayForCurrentUser(
|
||||
submission: UpdateActivityStatusSubmission,
|
||||
): Promise<ActivityRecord> {
|
||||
const user = await getAuthenticatedUser();
|
||||
|
||||
if (!user) {
|
||||
throw new Error("Er is geen ingelogde gebruiker beschikbaar.");
|
||||
}
|
||||
|
||||
const profileBundle = await ensureProfileBundleForCurrentUser();
|
||||
|
||||
if (!profileBundle) {
|
||||
throw new Error("Profielbundle ontbreekt voor de huidige gebruiker.");
|
||||
}
|
||||
|
||||
const activityDate = getLocalDateForTimezone(profileBundle.profile.timezone);
|
||||
const supabase = await createClient();
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from("activities")
|
||||
.update({
|
||||
status: submission.status,
|
||||
})
|
||||
.eq("id", submission.activityId)
|
||||
.eq("user_id", user.id)
|
||||
.eq("activity_date", activityDate)
|
||||
.select(ACTIVITY_COLUMNS)
|
||||
.maybeSingle();
|
||||
|
||||
if (error) {
|
||||
throw new Error(`Activiteitstatus kon niet worden opgeslagen: ${error.message}`);
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
throw new Error("Ongeldige of niet-beschikbare activiteit.");
|
||||
}
|
||||
|
||||
return mapActivityRow(data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,11 @@ export type CreateActivitySubmission = {
|
|||
priorityLevel: ActivityPriorityLevel;
|
||||
};
|
||||
|
||||
export type UpdateActivityStatusSubmission = {
|
||||
activityId: string;
|
||||
status: ActivityStatus;
|
||||
};
|
||||
|
||||
export type ActivitiesForDateStatus = {
|
||||
timezone: string;
|
||||
activityDate: string;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue