-
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 #3 from timia2109/feature/mealplan-management
Feature/mealplan management
- Loading branch information
Showing
31 changed files
with
598 additions
and
118 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
"use server"; | ||
|
||
import { leaveMealPlan } from "@/dal/mealPlans/leaveMealPlan"; | ||
import { getUserId } from "@/functions/user/getUserId"; | ||
import { getLinkWithLocale } from "@/functions/user/redirectWithLocale"; | ||
import { revalidatePath } from "next/cache"; | ||
|
||
export async function leaveMealPlanAction(mealPlanId: string) { | ||
const user = await getUserId(); | ||
if (user == null) return; | ||
|
||
await leaveMealPlan(mealPlanId, user); | ||
revalidatePath(getLinkWithLocale("/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,17 @@ | ||
"use server"; | ||
|
||
import { setMealPlanAsDefault } from "@/dal/mealPlans/setMealPlanAsDefault"; | ||
import { getUserId } from "@/functions/user/getUserId"; | ||
import { getLinkWithLocale } from "@/functions/user/redirectWithLocale"; | ||
import { revalidatePath } from "next/cache"; | ||
|
||
export async function setDefaultMealPlan(mealPlanId: string) { | ||
const userId = await getUserId(); | ||
if (userId == null) | ||
return { | ||
message: "Login expected", | ||
}; | ||
|
||
await setMealPlanAsDefault(userId, mealPlanId); | ||
revalidatePath(getLinkWithLocale("/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,28 @@ | ||
import { MealPlanEntry } from "@/components/mealEntries/MealPlanEntry"; | ||
import { getMealPlans } from "@/dal/mealPlans/getMealPlans"; | ||
import { getUserId } from "@/functions/user/getUserId"; | ||
import { getScopedI18n } from "@/locales/server"; | ||
|
||
export default async function ManageMealPlansPage() { | ||
const userId = await getUserId(true); | ||
const mealPlanAssignments = await getMealPlans(userId); | ||
const t = await getScopedI18n("manageMealPlans"); | ||
|
||
return ( | ||
<div className="container mx-auto"> | ||
<h1 className="mb-1 text-3xl font-extrabold">{t("manage")}</h1> | ||
<title>{t("manage")}</title> | ||
<div> | ||
{mealPlanAssignments.map((assignment) => ( | ||
<MealPlanEntry | ||
key={assignment.mealPlanId} | ||
mealPlanAssignment={assignment} | ||
mealPlan={assignment.mealPlan} | ||
withActions | ||
withUsers | ||
/> | ||
))} | ||
</div> | ||
</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
3 changes: 3 additions & 0 deletions
3
src/app/[locale]/(userArea)/mealPlan/invite/[mealPlanId]/page.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,3 @@ | ||
export default function InvitePage() { | ||
return <div>InvitePage</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
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,20 @@ | ||
import Link from "next/link"; | ||
|
||
export default function NotFound() { | ||
return ( | ||
<div className="hero min-h-screen bg-base-200"> | ||
<title>Not found</title> | ||
<div className="hero-content text-center"> | ||
<div className="max-w-md"> | ||
<h1 className="bg-gradient-to-r from-pink-500 to-purple-600 bg-clip-text text-5xl font-bold text-transparent"> | ||
404 Not Found | ||
</h1> | ||
<p className="py-6">Could not find requested resource.</p> | ||
<Link className="btn btn-outline btn-primary" href="/"> | ||
Return Home | ||
</Link> | ||
</div> | ||
</div> | ||
</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,41 @@ | ||
"use client"; | ||
|
||
import { useScopedI18n } from "@/locales/client"; | ||
import type { FC, PropsWithChildren } from "react"; | ||
|
||
type Props = { | ||
onConfirm: () => void; | ||
onCancel: () => void; | ||
}; | ||
|
||
/** Generic confirm modal. Gets visible, when its rendered */ | ||
export const ConfirmationModal: FC<PropsWithChildren<Props>> = ({ | ||
children, | ||
onCancel, | ||
onConfirm, | ||
}) => { | ||
const t = useScopedI18n("confirmModal"); | ||
|
||
return ( | ||
<dialog className="modal" open> | ||
<div className="modal-box"> | ||
{children} | ||
<div className="modal-action"> | ||
<form method="dialog"> | ||
<div className="join"> | ||
<button className="btn btn-primary join-item" onClick={onConfirm}> | ||
{t("confirm")} | ||
</button> | ||
<button | ||
className="btn btn-outline btn-secondary join-item" | ||
onClick={onCancel} | ||
> | ||
{t("cancel")} | ||
</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</dialog> | ||
); | ||
}; |
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,21 @@ | ||
import type { FC } from "react"; | ||
|
||
type Props = { | ||
name: string; | ||
}; | ||
|
||
const initialsRegex = /(\w).+ (\w)/; | ||
|
||
export const NameProfileImage: FC<Props> = ({ name }) => { | ||
const regexResult = name.match(initialsRegex); | ||
const initials = | ||
regexResult != null ? regexResult[1] + regexResult[2] : name[0] + name[1]; | ||
|
||
return ( | ||
<div className="avatar placeholder"> | ||
<div className="w-10 rounded-full bg-neutral text-neutral-content"> | ||
<span>{initials}</span> | ||
</div> | ||
</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
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,27 @@ | ||
import type { User } from "next-auth"; | ||
import Image from "next/image"; | ||
import type { FC } from "react"; | ||
import { NameProfileImage } from "./NameProfileImage"; | ||
|
||
export type UserLike = Pick<User, "name" | "image">; | ||
|
||
type Props = { | ||
user: UserLike; | ||
size: number; | ||
}; | ||
|
||
export const ProfileImage: FC<Props> = ({ user, size }) => { | ||
if (user.image == null) return <NameProfileImage name={user.name ?? "??"} />; | ||
|
||
return ( | ||
<div className="avatar"> | ||
<Image | ||
src={user.image} | ||
alt={user.name ?? "??"} | ||
width={size} | ||
height={size} | ||
className="w-10 rounded-full ring ring-primary ring-offset-2 ring-offset-base-100" | ||
/> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.