-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathbirthday-picker.tsx
38 lines (33 loc) · 1023 Bytes
/
birthday-picker.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React from "react";
import { Section, DatePicker, Message, PheliaMessageProps } from "../../core";
const delay = (ms: number) => new Promise(res => setTimeout(res, ms));
export function BirthdayPicker({ useState }: PheliaMessageProps) {
const [birth, setBirth] = useState("birth");
const [user, setUser] = useState("user");
const today = new Date().toISOString().split("T")[0];
const birthdayIsToday = birth === today;
return (
<Message text="Gimme yo birthday">
<Section
text={
birth
? birthdayIsToday
? `Happy birthday ${user}!`
: `Your birthday is on ${birth}.`
: "Select your birthday."
}
accessory={
<DatePicker
initialDate={birth}
onSelect={async ({ user, date }) => {
await delay(2000);
setBirth(date);
setUser(user.username);
}}
action="date"
/>
}
/>
</Message>
);
}