From f144a9803c8b7b61ed66c11c43a1d95b8429b133 Mon Sep 17 00:00:00 2001 From: Srdjan Date: Sat, 31 Aug 2024 02:42:29 +0200 Subject: [PATCH] MODIFY: actions now return better, succinct error and success messages --- src/util/actions/profile.ts | 6 +++--- src/util/actions/workout.ts | 28 ++++++++++++++-------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/util/actions/profile.ts b/src/util/actions/profile.ts index 9388589a..0720349e 100644 --- a/src/util/actions/profile.ts +++ b/src/util/actions/profile.ts @@ -32,20 +32,20 @@ export async function updateUserTimeFormatPreference( .set({ preferences: { ...user.preferences, timeFormat: value } }) .where(eq(users.id, user.id)); - console.log(`Time format set to - ${value}`); + console.log(`Time format - ${value}`); revalidatePath("/profile"); return { status: "success", - message: `Time format set to - ${value}`, + message: `Time format - ${value}`, }; } catch (error) { console.log(error); return { status: "error", - message: "Database Error: Time format could not be changed", + message: "Failed to set new time format...", }; } } diff --git a/src/util/actions/workout.ts b/src/util/actions/workout.ts index 08557a15..4f8ec8b7 100644 --- a/src/util/actions/workout.ts +++ b/src/util/actions/workout.ts @@ -27,7 +27,7 @@ export async function createWorkout( return { status: "error", errors: isValidWorkout.error.flatten().fieldErrors, - message: "Workout could not be created", + message: "Invalid workout data", }; } @@ -50,7 +50,7 @@ export async function createWorkout( errors: { title: ["Workout with this title already exists."], }, - message: `"${title}" workout already exists`, + message: `${title} workout already exists`, }; } @@ -66,14 +66,14 @@ export async function createWorkout( revalidatePath("/home"); return { - status: "success", + status: "success-redirect", message: `${title} workout created`, }; } catch (error) { console.log(error); return { status: "error", - message: "Database Error: Workout could not be created", + message: "Failed to create workout...", }; } } @@ -95,7 +95,7 @@ export async function editWorkout( return { status: "error", errors: isValidWorkout.error.flatten().fieldErrors, - message: "Workout could not be edited", + message: "Invalid workout data", }; } @@ -142,7 +142,7 @@ export async function editWorkout( console.log(error); return { status: "error", - message: "Database Error: Workout could not be edited", + message: "Failed to edit workout", }; } } @@ -166,7 +166,7 @@ export async function removeWorkout( console.error(err); return { status: "error", - message: "Database Error: Workout could not be removed", + message: "Failed to remove workout...", }; } } @@ -193,7 +193,7 @@ export async function archiveWorkout( console.error(err); return { status: "error", - message: "Database Error: Workout could not be archived", + message: "Failed to archive workout", }; } } @@ -238,13 +238,13 @@ export async function submitDoneWorkout( return { status: "success-redirect", - message: "Workout completed", + message: "Workout submitted", }; } catch (error) { console.log(error); return { status: "error", - message: "Workout not completed", + message: "Failed to submit workout...", }; } } @@ -265,7 +265,7 @@ export async function updateCurrentWorkout( return { status: "error", errors: isValidWorkout.error.flatten().fieldErrors, - message: `${updatedCurrentWorkout.title} workout was not updated`, + message: `${updatedCurrentWorkout.title} was not updated`, }; } @@ -275,19 +275,19 @@ export async function updateCurrentWorkout( .set({ exercises: [...updatedCurrentWorkout.exercises] }) .where(and(eq(workouts.id, workoutId), eq(workouts.status, "current"))); - console.log("Workout successfully updated."); + console.log("Workout updated."); revalidatePath("/home"); return { status: "success-redirect", - message: `${updatedCurrentWorkout.title} workout successfully updated`, + message: `${updatedCurrentWorkout.title} workout updated`, }; } catch (error) { console.error(error); return { status: "error", - message: "Database Error: Workout could not be updated", + message: "Failed to update workout...", }; } }