diff --git a/app/pufflings/family/[id]/child/[childId]/dashboard/page.tsx b/app/pufflings/family/[id]/child/[childId]/dashboard/page.tsx index 74105c5..9b64244 100644 --- a/app/pufflings/family/[id]/child/[childId]/dashboard/page.tsx +++ b/app/pufflings/family/[id]/child/[childId]/dashboard/page.tsx @@ -1,13 +1,16 @@ 'use server'; import FeedChart from '@/app/ui/charts/feedChart'; +import DeleteButton from '@/app/ui/deleteButton'; import Recents from '@/app/ui/recents'; +import { getChild } from '@/lib/child'; import { getChildDashboard, LastDiaper, LastFeed, LastSleep, } from '@/lib/dashboard'; +import Link from 'next/link'; const Dashboard = async ({ params: { childId, id }, @@ -18,6 +21,8 @@ const Dashboard = async ({ parseInt(childId) ); + const childInfo = await getChild(parseInt(childId)); + return (
+
+ + view {childInfo?.name.toLocaleLowerCase()}'s profile + + +
); }; diff --git a/app/pufflings/family/[id]/child/[childId]/diapers/page.tsx b/app/pufflings/family/[id]/child/[childId]/diapers/page.tsx index ed7b2cf..f65a3d7 100644 --- a/app/pufflings/family/[id]/child/[childId]/diapers/page.tsx +++ b/app/pufflings/family/[id]/child/[childId]/diapers/page.tsx @@ -5,7 +5,7 @@ import { faDroplet } from '@fortawesome/free-solid-svg-icons'; import { faPoop } from '@fortawesome/free-solid-svg-icons'; import { dateFormatter } from '@/lib/dateFormatter'; import { timeFormatter } from '@/lib/timeFormatter'; -import BackButton from '@/app/ui/backButton'; +import BackToChildButton from '@/app/ui/backToChildButton'; export default async function Diapers({ params: { childId, id }, @@ -25,7 +25,7 @@ export default async function Diapers({ diapers
- +
{feedInfo && }
- +
- +
{dateFormatter.format(dateTime)}
diff --git a/app/pufflings/family/[id]/child/[childId]/profile/page.tsx b/app/pufflings/family/[id]/child/[childId]/profile/page.tsx index 569108b..b9e7889 100644 --- a/app/pufflings/family/[id]/child/[childId]/profile/page.tsx +++ b/app/pufflings/family/[id]/child/[childId]/profile/page.tsx @@ -5,8 +5,12 @@ import { lastCreatedWeight } from '@/lib/weight'; import Link from 'next/link'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faPenToSquare } from '@fortawesome/free-solid-svg-icons'; -import { calculateAge, getMonthsDifference } from '@/lib/currentAge'; -import BackButton from '@/app/ui/backButton'; +import { + calculateAge, + getMonthsDifference, + getWeeksDifference, +} from '@/lib/currentAge'; +import BackToChildButton from '@/app/ui/backToChildButton'; const childProfilePage = async ({ params: { childId, id }, @@ -36,18 +40,48 @@ const childProfilePage = async ({ if (currentAge >= 1) { let childsAge = currentAge; ageDisplay = `${childsAge} years`; + } else if (currentAge == 1) { + let childsAge = currentAge; + ageDisplay = `${childsAge} year`; } else if (currentAge < 1) { let childsAge = getMonthsDifference(date); - ageDisplay = `${childsAge} months`; + if (childsAge < 1) { + let childWeeks = getWeeksDifference(date); + if (childWeeks == 1) { + ageDisplay = `${childWeeks} week`; + } else ageDisplay = `${childWeeks} weeks`; + } else if (childsAge == 1) { + ageDisplay = `${childsAge} month`; + } else ageDisplay = `${childsAge} months`; } const editIcon = ; + let weightDisplay = ''; + + if (currentWeight.pounds && currentWeight.ounces) { + weightDisplay = `${currentWeight?.pounds} lbs ${currentWeight?.ounces} oz`; + } else if (currentWeight.pounds && !currentWeight.ounces) { + weightDisplay = `${currentWeight?.pounds} lbs`; + } else if (!currentWeight.pounds && currentWeight.ounces) { + weightDisplay = `${currentWeight?.ounces} oz`; + } + + let heightDisplay = ''; + + if (currentHeight.feet && currentHeight.inches) { + heightDisplay = `${currentHeight?.feet} ft ${currentHeight?.inches} in`; + } else if (currentHeight.feet && !currentHeight.inches) { + heightDisplay = `${currentHeight?.feet} ft`; + } else if (!currentHeight.feet && currentHeight.inches) { + heightDisplay = `${currentHeight?.inches} in`; + } + if (currentHeight && currentWeight) { return (
- +

@@ -57,7 +91,7 @@ const childProfilePage = async ({

age: {ageDisplay}

birthday: {formattedBirthday}

- height: {currentHeight?.feet} ft {currentHeight?.inches} in + height: {heightDisplay}

- weight: {currentWeight?.pounds} lbs {currentWeight?.ounces} oz + weight: {weightDisplay}

- +

@@ -102,7 +136,7 @@ const childProfilePage = async ({

- weight: {currentWeight?.pounds} lbs {currentWeight?.ounces} oz + weight: {weightDisplay}

- +

@@ -129,7 +163,7 @@ const childProfilePage = async ({

age: {ageDisplay}

birthday: {formattedBirthday}

- height: {currentHeight?.feet} ft {currentHeight?.inches} in + height: {heightDisplay}

- +

diff --git a/app/pufflings/family/[id]/child/[childId]/sleeps/page.tsx b/app/pufflings/family/[id]/child/[childId]/sleeps/page.tsx index 229d89f..734af92 100644 --- a/app/pufflings/family/[id]/child/[childId]/sleeps/page.tsx +++ b/app/pufflings/family/[id]/child/[childId]/sleeps/page.tsx @@ -3,7 +3,7 @@ import Link from 'next/link'; import { dateFormatter } from '@/lib/dateFormatter'; import { timeFormatter } from '@/lib/timeFormatter'; import { lastCreatedSleep } from '@/lib/sleep'; -import BackButton from '@/app/ui/backButton'; +import BackToChildButton from '@/app/ui/backToChildButton'; export default async function Sleeps({ params: { childId, id }, @@ -22,7 +22,7 @@ export default async function Sleeps({ sleeps

- +
+ previous page + + ); +} diff --git a/app/ui/deleteButton.tsx b/app/ui/deleteButton.tsx index 51e725a..0c1b163 100644 --- a/app/ui/deleteButton.tsx +++ b/app/ui/deleteButton.tsx @@ -15,7 +15,7 @@ const DeleteButton = ({ return ( diff --git a/app/ui/recents.tsx b/app/ui/recents.tsx index 27154dd..3bf7cae 100644 --- a/app/ui/recents.tsx +++ b/app/ui/recents.tsx @@ -35,7 +35,7 @@ const Recents = ({ amount
- {lastFeed.amount?.toString()} oz + {lastFeed?.amount?.toString()} oz
diff --git a/lib/currentAge.ts b/lib/currentAge.ts index 040c624..6131f77 100644 --- a/lib/currentAge.ts +++ b/lib/currentAge.ts @@ -26,3 +26,19 @@ export const getMonthsDifference = (birthday: Date) => { return monthsDiff; }; + +export const getWeeksDifference = (birthday: Date) => { + const birthDate = new Date(birthday); + + // Set the time component of the birthDate to midnight + birthDate.setHours(0, 0, 0, 0); + + const today = new Date(); + // Set the time component of today to midnight + today.setHours(0, 0, 0, 0); + + const timeDiff = today.getTime() - birthDate.getTime(); + const weeksDiff = Math.floor(timeDiff / (1000 * 60 * 60 * 24 * 7)); + + return weeksDiff; +};