/
LogPage.tsx
34 lines (32 loc) · 985 Bytes
/
LogPage.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
import React from "react";
import { Button } from "semantic-ui-react";
import { useUser } from "./useUser";
import { Redirect } from "react-router-dom";
import { useLogAttendance } from "./useAttendances";
import { AttendanceType } from "./attendance";
export function LogPage() {
const { data, loading } = useUser();
const { logAttendance, loading: loggingAttendance } = useLogAttendance();
if (loading) {
return <div>loading...</div>;
}
if (!data) {
return <Redirect to="/signin" />;
}
const handleAttendClick = async () => {
await logAttendance(data.userId, AttendanceType.Arrive);
};
const handleLeaveClick = async () => {
await logAttendance(data.userId, AttendanceType.Leave);
};
return (
<div>
<Button primary onClick={handleAttendClick} disabled={loggingAttendance}>
Attend
</Button>
<Button secondary onClick={handleLeaveClick} disabled={loggingAttendance}>
Leave
</Button>
</div>
);
}