-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from timia2109/feature/meal-plan-creation
Feature/meal plan creation
- Loading branch information
Showing
55 changed files
with
749 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"use server"; | ||
|
||
import { createMealPlan } from "@/dal/mealPlans/createMealPlan"; | ||
import { getUserId } from "@/functions/user/getUserId"; | ||
import { revalidateRoute } from "@/routes"; | ||
import { z } from "zod"; | ||
import { zfd } from "zod-form-data"; | ||
|
||
const schema = zfd.formData({ | ||
mealPlanName: z.string(), | ||
}); | ||
|
||
export async function createMealPlanAction(formData: FormData) { | ||
const { mealPlanName } = schema.parse(formData); | ||
const user = await getUserId(null); | ||
|
||
await createMealPlan(user, mealPlanName, false); | ||
revalidateRoute("manage"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"use server"; | ||
|
||
import { getMealPlan } from "@/dal/mealPlans/getMealPlan"; | ||
import { renameMealPlan } from "@/dal/mealPlans/renameMealPlan"; | ||
import { getUserId } from "@/functions/user/getUserId"; | ||
import { revalidateRoute } from "@/routes"; | ||
import { z } from "zod"; | ||
import { zfd } from "zod-form-data"; | ||
|
||
const schema = zfd.formData({ | ||
mealPlanName: z.string(), | ||
mealPlanId: z.string().length(25), | ||
}); | ||
|
||
export async function renameMealPlanAction(formData: FormData) { | ||
const { mealPlanName, mealPlanId } = schema.parse(formData); | ||
const user = await getUserId(null); | ||
|
||
const mealPlan = await getMealPlan(user, mealPlanId); | ||
if (mealPlan === null) { | ||
throw new Error("Meal plan not found"); | ||
} | ||
|
||
await renameMealPlan(mealPlanId, mealPlanName); | ||
revalidateRoute("manage"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"use server"; | ||
|
||
import { setPreference } from "@/functions/user/preferences"; | ||
|
||
export async function setCalendarLayoutAction(layout: string) { | ||
setPreference("calendarLayout", layout); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"use server"; | ||
|
||
import { setPreference } from "@/functions/user/preferences"; | ||
|
||
export async function setThemeAction(theme: string) { | ||
setPreference("theme", theme); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/app/[locale]/(userArea)/profile/CalendarLayoutSelection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"use client"; | ||
|
||
import { setCalendarLayoutAction } from "@/actions/setCalendarLayoutAction"; | ||
import type { CalendarLayout } from "@/functions/user/preferences"; | ||
import { useScopedI18n } from "@/locales/client"; | ||
import classNames from "classnames"; | ||
import type { FC } from "react"; | ||
|
||
const CalendarPreference: FC<{ | ||
currentValue: CalendarLayout; | ||
value: CalendarLayout; | ||
label: string; | ||
}> = ({ value, label, currentValue }) => ( | ||
<button | ||
onClick={() => setCalendarLayoutAction(value)} | ||
className={classNames({ | ||
"btn join-item": true, | ||
"btn-active": value == currentValue, | ||
})} | ||
> | ||
{label} | ||
</button> | ||
); | ||
|
||
export const CalendarLayoutSelection: FC<{ current: CalendarLayout }> = ({ | ||
current, | ||
}) => { | ||
const t = useScopedI18n("profile"); | ||
|
||
return ( | ||
<div className="join join-vertical"> | ||
<CalendarPreference | ||
currentValue={current} | ||
value="RESPONSIVE" | ||
label={t("calendarLayoutResponsive")} | ||
/> | ||
<CalendarPreference | ||
currentValue={current} | ||
value="FIXED" | ||
label={t("calendarLayoutFixed")} | ||
/> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"use client"; | ||
|
||
import { setThemeAction } from "@/actions/setThemeAction"; | ||
import type { FC } from "react"; | ||
|
||
export const SelectableTheme: FC<{ theme: string; active: boolean }> = ({ | ||
theme, | ||
active, | ||
}) => ( | ||
<input | ||
type="radio" | ||
name="selectedTheme" | ||
className="theme-controller btn join-item" | ||
aria-label={theme} | ||
checked={active} | ||
onChange={() => setThemeAction(theme)} | ||
value={theme} | ||
/> | ||
); |
Oops, something went wrong.