forked from electerious/Ackee
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRouteSettings.js
More file actions
128 lines (102 loc) · 3.83 KB
/
RouteSettings.js
File metadata and controls
128 lines (102 loc) · 3.83 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
import { createElement as h, Fragment, useEffect } from 'react'
import { version, homepage } from '../../../../../package.json'
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 FetchingMessage = (props) => {
return h(Message, { status: 'warning' }, `Fetching ${ props.label }...`)
}
const RouteSettings = (props) => {
useEffect(() => {
props.fetchDomains(props)
props.fetchEvents(props)
props.fetchPermanentTokens(props)
}, [])
const showModal = (type, data = {}) => {
props.addModalsModal({
type,
props: data
})
}
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 = () => showModal(MODALS_DOMAIN_ADD)
const showDomainEditModal = (domain) => showModal(MODALS_DOMAIN_EDIT, domain)
const showEventAddModal = () => showModal(MODALS_EVENT_ADD)
const showEventEditModal = (event) => showModal(MODALS_EVENT_EDIT, event)
const showPermanentTokenAddModal = () => showModal(MODALS_PERMANENT_TOKEN_ADD)
const showPermanentTokenEditModal = (permanentToken) => showModal(MODALS_PERMANENT_TOKEN_EDIT, permanentToken)
const domainsFetching = h(FetchingMessage, { label: 'domains' })
const eventsFetching = h(FetchingMessage, { label: 'events' })
const permanentTokensFetching = h(FetchingMessage, { label: 'permanent tokens' })
const domainsItems = createItems(props.domains.value, showDomainEditModal, showDomainAddModal, 'New domain')
const eventsItems = createItems(props.events.value, showEventEditModal, showEventAddModal, 'New event')
const permanentTokensItems = createItems(props.permanentTokens.value, showPermanentTokenEditModal, showPermanentTokenAddModal, 'New permanent token')
return (
h(Fragment, {},
h(CardSetting, {
headline: 'Account'
},
h(LinkItem, { type: 'p', disabled: true, text: version }, 'Version'),
...(!window.env.authDisabled ? [
h(LinkItem, { type: 'button', onClick: () => props.deleteToken(props) }, 'Sign Out'),
h(Line)
] : [])
),
h(CardSetting, {
headline: 'Domains'
},
...(props.domains.fetching === true ? [ domainsFetching ] : domainsItems)
),
h(CardSetting, {
headline: 'Events'
},
...(props.events.fetching === true ? [ eventsFetching ] : eventsItems)
),
h(CardSetting, {
headline: 'Permanent Tokens'
},
...(props.permanentTokens.fetching === true ? [ permanentTokensFetching ] : 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')
)
)
)
}
export default RouteSettings