Skip to content

Commit

Permalink
chore(website): refine AlertCard (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Mar 4, 2023
1 parent a973f04 commit 65f99ae
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions packages/website/components/AlertCard/index.tsx
@@ -1,21 +1,28 @@
import dayjs from "dayjs";
import Dayjs from "dayjs";

// TODO: support expiration time
export default function (props: {
updatedAt: Date;
createdAt: Date;
showExpirationReminder: boolean;
showExpirationReminder?: boolean;
expirationDays?: number;
}) {
if (!props.showExpirationReminder) return null;
const today = dayjs();
const diff = today.diff(props.createdAt, "days");
if (diff > 30) {
return (
<div className="warning-card text-gray-600 dark:text-dark">
<div>
请注意,本文编写于 {diff} 天前,最后修改于{" "}
{today.diff(props.updatedAt, "days")} 天前,其中某些信息可能已经过时。
if (props.showExpirationReminder) {
const dayjs = Dayjs();
const diff = dayjs.diff(props.createdAt, "days");

if (diff > (props.expirationDays || 30)) {
return (
<div className="warning-card text-gray-600 dark:text-dark">
<div>
请注意,本文编写于 {diff} 天前,最后修改于{" "}
{dayjs.diff(props.updatedAt, "days")}{" "}
天前,其中某些信息可能已经过时。
</div>
</div>
</div>
);
);
}
}

return null;
}

0 comments on commit 65f99ae

Please sign in to comment.