| Prompt | Step 1: The goals table already has goal_type, target_value, target_unit, start_date, and target_date. For frequency goals specifically, add a new column frequency_period (ENUM: 'week', 'month'), nullable, used only when goal_type = 'frequency'. This defines whether the goal resets/is measured on a calendar-week or calendar-month basis.
Don't build any goal creation or display logic yet — just add the column and confirm the migration runs cleanly.
Step 2: Build a "Create Goal" form, currently supporting only goal_type = 'frequency'. Fields:
- Title (required, text)
- Target count (required, number) → stored in
target_value
- Time frame (required, select: "per week" / "per month") → stored in
frequency_period
- Start date (default to today, editable) →
start_date
- Target/end date, auto-calculated from
start_date + one week or one month based on frequency_period (not manually entered) → target_date
On submit, insert into goals with user_id, goal_type = 'frequency', status = 'active', and the fields above. target_unit can be set to 'sessions' for now since only total workout count is supported.
Any completed workout session counts toward this goal — not tied to a specific plan.
Step 3:
Write a function/endpoint that calculates current progress for an active frequency goal:
- Determine the current window's start/end based on
frequency_period (calendar week or calendar month) relative to today.
- Count how many
workout_sessions rows exist for this user where status = 'completed' and started_at falls within the current window.
- Return the count alongside the goal's
target_value (e.g., "3 of 4").
Use the user's local time zone for window boundaries, not server time — [confirm how you're currently determining user time zone, e.g., browser-provided, or flag if this needs to default to UTC for now since the users table doesn't currently store one].
This should be computed fresh each time it's requested, not stored/cached in a separate table.
Step 4:
Add a "Goals" section to [wherever you want this — dashboard/home page and/or its own Goals tab]. For each active frequency goal, show:
- Title
- A progress bar or "X of Y workouts this week/month" counter, using the Step 3 calculation
- Days remaining in the current window (
target_date minus today)
List goals in order of soonest-ending first. Keep styling consistent with the rest of the app.
Step 5:
Add logic (e.g., a scheduled check, or a check-on-load) that updates a frequency goal's status once its target_date has passed:
- If the final progress count met or exceeded
target_value, set status = 'completed'.
- If it fell short, set
status = 'expired'.
- Completed/expired goals should no longer show in the active goals list, but should remain visible somewhere (e.g., a "past goals" view) showing their final result — don't delete the rows.
|
|---|