dynamic afternoon, morning, etc text
This commit is contained in:
@@ -13,10 +13,12 @@ import {
|
|||||||
import { useTeamDashboardContext } from "../../contexts/teamDashboardContext";
|
import { useTeamDashboardContext } from "../../contexts/teamDashboardContext";
|
||||||
import router from "next/router";
|
import router from "next/router";
|
||||||
import Moment from "react-moment";
|
import Moment from "react-moment";
|
||||||
|
import { User } from "../../models/user";
|
||||||
|
import { generateGreetings } from "../../helpers/dateTime";
|
||||||
|
|
||||||
export default function Header() {
|
export default function Header() {
|
||||||
const { logOut } = useAuth();
|
const { logOut } = useAuth();
|
||||||
const { team } = useTeamDashboardContext();
|
const { team, user } = useTeamDashboardContext();
|
||||||
|
|
||||||
async function handleSignOut() {
|
async function handleSignOut() {
|
||||||
console.log("clicked log out button");
|
console.log("clicked log out button");
|
||||||
@@ -30,14 +32,14 @@ export default function Header() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var today = new Date();
|
const today = new Date();
|
||||||
|
const periodOfDay = generateGreetings();
|
||||||
return (
|
return (
|
||||||
<section className="flex-1 flex flex-row items-center justify-between py-5">
|
<section className="flex-1 flex flex-row items-center justify-between py-5">
|
||||||
{/* welcome message */}
|
{/* welcome message */}
|
||||||
<span className="flex flex-col items-baseline">
|
<span className="flex flex-col items-baseline">
|
||||||
<span className="font-bold text-xl text-white">
|
<span className="font-bold text-xl text-white capitalize ">
|
||||||
👋Hey Arjun, Good Afternoon!
|
👋Hey {user.firstName}, {periodOfDay}!
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
{/* Date and time */}
|
{/* Date and time */}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import moment from "moment";
|
||||||
|
|
||||||
|
export function generateGreetings(): string {
|
||||||
|
const hour = moment().hour();
|
||||||
|
|
||||||
|
if (hour > 16) {
|
||||||
|
return "Good evening";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hour > 11) {
|
||||||
|
return "Good afternoon";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Good morning";
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user