forked from aeharding/voyager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccount.tsx
60 lines (52 loc) · 1.35 KB
/
Account.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import {
IonItem,
IonItemOption,
IonItemOptions,
IonItemSliding,
IonLabel,
IonRadio,
IonReorder,
IonText,
} from "@ionic/react";
import { RemoveItemButton } from "#/features/shared/ListEditor";
import { useAppDispatch } from "#/store";
import { Credential, logoutAccount } from "./authSlice";
interface AccountProps {
editing: boolean;
account: Credential;
allowEdit: boolean;
}
export default function Account({ editing, account, allowEdit }: AccountProps) {
const dispatch = useAppDispatch();
function logout() {
dispatch(logoutAccount(account.handle));
}
const isGuest = !account.jwt;
const label = (
<>
{account.handle} {isGuest && <IonText color="medium">(guest)</IonText>}
</>
);
return (
<IonItemSliding>
{allowEdit && (
<IonItemOptions side="end" onIonSwipe={logout}>
<IonItemOption color="danger" expandable onClick={logout}>
{isGuest ? "Remove" : "Log out"}
</IonItemOption>
</IonItemOptions>
)}
<IonItem>
{editing && <RemoveItemButton />}
{editing ? (
<>
<IonLabel className="ion-text-nowrap">{label}</IonLabel>
<IonReorder slot="end" />
</>
) : (
<IonRadio value={account.handle}>{label}</IonRadio>
)}
</IonItem>
</IonItemSliding>
);
}