-
-
Notifications
You must be signed in to change notification settings - Fork 387
Expand file tree
/
Copy pathRouteSettings.js
More file actions
139 lines (118 loc) · 4.45 KB
/
RouteSettings.js
File metadata and controls
139 lines (118 loc) · 4.45 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import { createElement as h, Fragment } from 'react'
import PropTypes from 'prop-types'
import { version, homepage } from '../../../../../package.json'
import useDeleteToken from '../../api/hooks/tokens/useDeleteToken'
import useDomains from '../../api/hooks/domains/useDomains'
import useEvents from '../../api/hooks/events/useEvents'
import usePermanentTokens from '../../api/hooks/permanentTokens/usePermanentTokens'
import {
MODALS_DOMAIN_ADD,
MODALS_DOMAIN_EDIT,
MODALS_EVENT_ADD,
MODALS_EVENT_EDIT,
MODALS_PERMANENT_TOKEN_ADD,
MODALS_PERMANENT_TOKEN_EDIT,
} from '../../constants/modals'
import CardSetting from '../cards/CardSetting'
import LinkItem from '../LinkItem'
import Line from '../Line'
import Message from '../Message'
const LoadingMessage = (props) => {
return h(Message, { status: 'warning' }, `Loading ${ props.label }...`)
}
const RouteSettings = (props) => {
const deleteToken = useDeleteToken()
const domains = useDomains()
const events = useEvents()
const permanentTokens = usePermanentTokens()
const onSignOut = async () => {
await deleteToken.mutate({
variables: {
id: props.token,
},
})
props.reset()
}
const createItems = (items, editFn, createFn, createLabel) => [
...items.map(
(item) => [
h(LinkItem, {
type: 'button',
text: item.id,
onClick: () => editFn(item),
}, item.title),
h(Line),
],
).flat(),
h(LinkItem, { type: 'button', onClick: createFn }, createLabel),
]
const showDomainAddModal = () => props.addModal(MODALS_DOMAIN_ADD)
const showDomainEditModal = (domain) => props.addModal(MODALS_DOMAIN_EDIT, domain)
const showEventAddModal = () => props.addModal(MODALS_EVENT_ADD)
const showEventEditModal = (event) => props.addModal(MODALS_EVENT_EDIT, event)
const showPermanentTokenAddModal = () => props.addModal(MODALS_PERMANENT_TOKEN_ADD)
const showPermanentTokenEditModal = (permanentToken) => props.addModal(MODALS_PERMANENT_TOKEN_EDIT, permanentToken)
const domainsLoading = h(LoadingMessage, { label: 'domains' })
const eventsLoading = h(LoadingMessage, { label: 'events' })
const permanentTokensLoading = h(LoadingMessage, { label: 'permanent tokens' })
const domainsItems = createItems(domains.value, showDomainEditModal, showDomainAddModal, 'New domain')
const eventsItems = createItems(events.value, showEventEditModal, showEventAddModal, 'New event')
const permanentTokensItems = createItems(permanentTokens.value, showPermanentTokenEditModal, showPermanentTokenAddModal, 'New permanent token')
const accountCard = window.env.isAnonymousMode ?
h(CardSetting, {
headline: 'Account',
},
h(LinkItem, { type: 'p', disabled: true, text: version }, 'Version'),
) :
h(CardSetting, {
headline: 'Account',
},
h(LinkItem, { type: 'p', disabled: true, text: version }, 'Version'),
h(Line),
h(LinkItem, { type: 'button', onClick: onSignOut }, 'Sign Out'),
)
return (
h(Fragment, {},
accountCard,
h(CardSetting, {
headline: 'Domains',
},
...(domains.status.isInitializing === true ? [ domainsLoading ] : domainsItems),
),
h(CardSetting, {
headline: 'Events',
},
...(events.status.isInitializing === true ? [ eventsLoading ] : eventsItems),
),
h(CardSetting, {
headline: 'Permanent Tokens',
},
...(permanentTokens.status.isInitializing === true ? [ permanentTokensLoading ] : permanentTokensItems),
),
h(CardSetting, {
headline: 'Donate',
},
h(LinkItem, { type: 'a', href: 'https://github.com/sponsors/electerious', target: '_blank', rel: 'noopener' }, 'Become a GitHub sponsor'),
h(Line),
h(LinkItem, { type: 'a', href: 'https://www.buymeacoffee.com/electerious', target: '_blank', rel: 'noopener' }, 'Buy me a coffee'),
h(Line),
h(LinkItem, { type: 'a', href: 'https://paypal.me/electerious', target: '_blank', rel: 'noopener' }, 'Donate via PayPal'),
),
h(CardSetting, {
headline: 'Help',
},
h(LinkItem, { type: 'a', href: 'https://ackee.electerious.com', target: '_blank', rel: 'noopener' }, 'Website and documentation'),
h(Line),
h(LinkItem, { type: 'a', href: homepage, target: '_blank', rel: 'noopener' }, 'Ackee on GitHub'),
h(Line),
h(LinkItem, { type: 'a', href: 'https://github.com/electerious/ackee-tracker', target: '_blank', rel: 'noopener' }, 'Add Ackee to your sites'),
),
)
)
}
RouteSettings.propTypes = {
reset: PropTypes.func.isRequired,
token: PropTypes.string.isRequired,
addModal: PropTypes.func.isRequired,
}
export default RouteSettings