|
@@ -1,23 +1,44 @@
|
|
|
-"use client";
|
|
|
|
|
-// import { useState, useEffect } from "react";
|
|
|
|
|
-// import { clientFetch } from "@/lib/restApiClient";
|
|
|
|
|
import Image from "next/image";
|
|
import Image from "next/image";
|
|
|
|
|
+import { restApiFetch } from "@utils/bagisto/index";
|
|
|
|
|
|
|
|
-const BIRTH_MONTH = 3;
|
|
|
|
|
-const BIRTH_DAY = 22;
|
|
|
|
|
-
|
|
|
|
|
|
|
+// 格式化日期为 "Apr. 22" 这种英文短格式
|
|
|
|
|
+function formatBirthdayDisplay(isoDate: string) {
|
|
|
|
|
+ if (!isoDate) return "";
|
|
|
|
|
+ const date = new Date(isoDate);
|
|
|
|
|
+ // 月份缩写 + 日期
|
|
|
|
|
+ return date.toLocaleDateString("en-US", {
|
|
|
|
|
+ month: "short",
|
|
|
|
|
+ day: "numeric",
|
|
|
|
|
+ });
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
-function isTodayBirthday(): boolean {
|
|
|
|
|
|
|
+// 判断今天是否是生日(只对比月、日,忽略年份)
|
|
|
|
|
+function isTodayBirthday(isoDate: string): boolean {
|
|
|
|
|
+ if (!isoDate) return false;
|
|
|
const now = new Date();
|
|
const now = new Date();
|
|
|
|
|
+ const birthDate = new Date(isoDate);
|
|
|
const currentMonth = now.getMonth();
|
|
const currentMonth = now.getMonth();
|
|
|
const currentDate = now.getDate();
|
|
const currentDate = now.getDate();
|
|
|
- return currentMonth === BIRTH_MONTH && currentDate === BIRTH_DAY;
|
|
|
|
|
|
|
+ const birthMonth = birthDate.getMonth();
|
|
|
|
|
+ const birthDay = birthDate.getDate();
|
|
|
|
|
+ return currentMonth === birthMonth && currentDate === birthDay;
|
|
|
}
|
|
}
|
|
|
-export default function GetPoints() {
|
|
|
|
|
- const isBirthdayToday = isTodayBirthday();
|
|
|
|
|
|
|
+
|
|
|
|
|
+export default async function GetPoints() {
|
|
|
|
|
+ const res = await restApiFetch({
|
|
|
|
|
+ api: `/customer/birthday`,
|
|
|
|
|
+ method: "GET",
|
|
|
|
|
+ isRoute: false,
|
|
|
|
|
+ });
|
|
|
|
|
+ console.log("res----------------aaa", res);
|
|
|
|
|
+
|
|
|
|
|
+ // 从接口拿生日字符串,示例:"1998-10-08"
|
|
|
|
|
+ const birthDateStr = res?.body?.data?.date_of_birth ?? "";
|
|
|
|
|
+ const isBirthdayToday = isTodayBirthday(birthDateStr);
|
|
|
|
|
+ const birthdayDisplayText = formatBirthdayDisplay(birthDateStr);
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
- <div className="w-full min-h-screen bg-white h-full">
|
|
|
|
|
|
|
+ <div className="w-full min-h-screen bg-white h-full">
|
|
|
<h1 className="font-normal text-2xl leading-ly-28 mb-6">
|
|
<h1 className="font-normal text-2xl leading-ly-28 mb-6">
|
|
|
Birthday Rewards
|
|
Birthday Rewards
|
|
|
</h1>
|
|
</h1>
|
|
@@ -35,12 +56,10 @@ export default function GetPoints() {
|
|
|
: "Birthday upcoming notice"
|
|
: "Birthday upcoming notice"
|
|
|
}
|
|
}
|
|
|
fill
|
|
fill
|
|
|
- className="object‑contain"
|
|
|
|
|
|
|
+ className="object-contain"
|
|
|
priority
|
|
priority
|
|
|
/>
|
|
/>
|
|
|
-
|
|
|
|
|
{isBirthdayToday ? (
|
|
{isBirthdayToday ? (
|
|
|
-
|
|
|
|
|
<>
|
|
<>
|
|
|
<div className="absolute top-[44%] left-1/2 -translate-x-1/2 w-[62%] text-center text-white text-md md:text-lg font-medium">
|
|
<div className="absolute top-[44%] left-1/2 -translate-x-1/2 w-[62%] text-center text-white text-md md:text-lg font-medium">
|
|
|
A Little Birthday Gift, Just for You
|
|
A Little Birthday Gift, Just for You
|
|
@@ -53,15 +72,15 @@ export default function GetPoints() {
|
|
|
</div>
|
|
</div>
|
|
|
</>
|
|
</>
|
|
|
) : (
|
|
) : (
|
|
|
-
|
|
|
|
|
<>
|
|
<>
|
|
|
<div className="absolute top-[51%] left-1/2 -translate-x-1/2 w-[60%] text-center text-white text-md md:text-lg leading-relaxed">
|
|
<div className="absolute top-[51%] left-1/2 -translate-x-1/2 w-[60%] text-center text-white text-md md:text-lg leading-relaxed">
|
|
|
<p>Your special day is coming!</p>
|
|
<p>Your special day is coming!</p>
|
|
|
- <p>We'll be celebrating you all month long.</p>
|
|
|
|
|
|
|
+ <p>We'll be celebrating you all month long.</p>
|
|
|
<p>Your $15 Birthday Gift Card will be ready soon.</p>
|
|
<p>Your $15 Birthday Gift Card will be ready soon.</p>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
+ {/* 这里动态渲染生日,不再写死Apr.22 */}
|
|
|
<div className="absolute top-[75%] left-1/2 -translate-x-1/2 text-white text-xl font-bold">
|
|
<div className="absolute top-[75%] left-1/2 -translate-x-1/2 text-white text-xl font-bold">
|
|
|
- [Apr. 22]
|
|
|
|
|
|
|
+ [{birthdayDisplayText}]
|
|
|
</div>
|
|
</div>
|
|
|
</>
|
|
</>
|
|
|
)}
|
|
)}
|