-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnav.go
More file actions
353 lines (334 loc) · 11.1 KB
/
Copy pathnav.go
File metadata and controls
353 lines (334 loc) · 11.1 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
package main
import (
"encoding/base64"
"log"
"github.com/maxence-charriere/go-app/v10/pkg/app"
shell "github.com/stateless-minds/go-ipfs-api"
)
type nav struct {
app.Compo
sh *shell.Shell
loggedIn bool
termsAccepted bool
isBusiness bool
isGovernment bool
businessName string
businessID string
entity string
userID string
plan Plan
}
func newNav() *nav {
return &nav{}
}
func (n *nav) OnMount(ctx app.Context) {
ctx.GetState("loggedIn", &n.loggedIn)
if n.loggedIn {
ctx.GetState("userID", &n.userID)
ctx.GetState("isBusiness", &n.isBusiness)
ctx.GetState("isGovernment", &n.isGovernment)
sh := shell.NewShell("localhost:5001")
n.sh = sh
}
ctx.ObserveState("termsAccepted", &n.termsAccepted)
ctx.ObserveState("entity", &n.entity)
ctx.ObserveState("businessName", &n.businessName)
ctx.ObserveState("businessID", &n.businessID)
ctx.ObserveState("plan", &n.plan)
}
func (n *nav) doOverlay(ctx app.Context, e app.Event) {
app.Window().GetElementByID("content").Get("classList").Call("toggle", "overlay")
}
func (n *nav) acceptTermsIndividual(ctx app.Context, e app.Event) {
e.PreventDefault()
ctx.SetState("termsAccepted", true)
app.Window().GetElementByID("main-menu").Call("click")
}
func (n *nav) acceptTermsBusiness(ctx app.Context, e app.Event) {
e.PreventDefault()
ctx.SetState("termsAccepted", true)
}
func (n *nav) deleteAccount(ctx app.Context, e app.Event) {
e.PreventDefault()
n.deleteUser()
n.deleteBalance()
// delete subscriptions
if n.isBusiness {
n.deletePlan()
// delete clients
// delete suppliers
}
ctx.DelState("termsAccepted")
ctx.Reload()
}
func (n *nav) deletePlan() {
err := n.sh.OrbitDocsDelete(dbPlan, n.plan.ID)
if err != nil {
log.Fatal(err)
}
}
func (n *nav) registerIndividual(ctx app.Context, e app.Event) {
e.PreventDefault()
ctx.SetState("entity", "individual")
}
func (n *nav) registerBusiness(ctx app.Context, e app.Event) {
e.PreventDefault()
ctx.SetState("entity", "business")
}
func (n *nav) submitBusinessID(ctx app.Context, e app.Event) {
validBusinessID := app.Window().GetElementByID("business-id").Call("reportValidity").Bool()
validBusinessName := app.Window().GetElementByID("business-name").Call("reportValidity").Bool()
if validBusinessID && validBusinessName {
businessName := app.Window().GetElementByID("business-name").Get("value").String()
associateName := app.Window().GetElementByID("associate-name").Get("value").String()
businessID := app.Window().GetElementByID("business-id").Get("value").String()
ctx.SetState("businessID", businessID)
ctx.SetState("businessName", businessName)
ctx.SetState("associateName", associateName).Persist()
app.Window().GetElementByID("main-menu").Call("click")
}
}
func (n *nav) deleteUser() {
userId := base64.StdEncoding.EncodeToString([]byte(n.userID))
err := n.sh.OrbitDocsDelete(dbUser, string(userId))
if err != nil {
log.Fatal(err)
}
}
func (n *nav) deleteBalance() {
err := n.sh.OrbitDocsDelete(dbWallet, n.userID)
if err != nil {
log.Fatal(err)
}
}
func (n *nav) Render() app.UI {
return app.Nav().Body(
app.Div().Class("navbar").Body(
app.Div().Class("container nav-container").Body(
app.If(n.loggedIn, func() app.UI {
return app.Input().ID("main-menu").Class("checkbox").Type("checkbox").Name("Main Menu").OnClick(n.doOverlay)
}).Else(func() app.UI {
return app.Input().ID("main-menu").Class("checkbox").Type("checkbox").Name("Main Menu").OnClick(n.doOverlay).Style("pointer-events", "none")
}),
app.If(n.loggedIn, func() app.UI {
return app.Div().Class("hamburger-lines").Body(
app.Span().Class("line line1"),
app.Span().Class("line line2"),
app.Span().Class("line line3"),
)
}).Else(func() app.UI {
return app.Div().Class("hamburger-lines").Body(
app.Span().Class("line line1"),
app.Span().Class("line line2"),
app.Span().Class("line line3"),
).Style("display", "none")
}),
app.If(!n.loggedIn, func() app.UI {
return app.If(!n.termsAccepted, func() app.UI {
return app.If(n.entity == "individual", func() app.UI {
return app.Div().Class("menu-items").Body(
app.Div().Class("header-summary").Body(
app.Span().Class("logo").Text("cyber-gubi"),
app.Div().Class("summary-text").Body(
app.Span().Text("Individual"),
),
),
app.Li().Body(
app.A().Href("/terms").Target("_blank").Text("Terms of Use"),
),
app.Li().Body(
app.A().Href("/privacy").Target("_blank").Text("Privacy"),
),
app.Li().Body(
app.A().Href("/cookie").Target("_blank").Text("Cookie"),
),
app.Div().Class("menu-btn").Body(
app.Button().ID("accept-terms").Class("submit").Type("submit").Text("Accept Terms").OnClick(n.acceptTermsIndividual),
),
)
}).ElseIf(n.entity == "business", func() app.UI {
return app.Div().Class("menu-items").Body(
app.Div().Class("header-summary").Body(
app.Span().Class("logo").Text("cyber-gubi"),
app.Div().Class("summary-text").Body(
app.Span().Text("Business"),
),
),
app.Li().Body(
app.A().Href("/terms-business").Target("_blank").Text("Terms of Use"),
),
app.Li().Body(
app.A().Href("/privacy").Target("_blank").Text("Privacy"),
),
app.Li().Body(
app.A().Href("/cookie").Target("_blank").Text("Cookie"),
),
app.Div().Class("menu-btn").Body(
app.Button().ID("accept-terms-business").Class("submit").Type("submit").Text("Accept Terms").OnClick(n.acceptTermsBusiness),
),
)
}).Else(func() app.UI {
return app.Div().Class("menu-items").Body(
app.Div().Class("header-summary").Body(
app.Span().Class("logo").Text("cyber-gubi"),
app.Div().Class("summary-text").Body(
app.Span().Text("Menu"),
),
),
app.Li().Body(
app.A().Text("For Individuals").OnClick(n.registerIndividual),
),
app.Li().Body(
app.Div().Class("tooltip").DataSet("direction", "bottom").Body(
app.Div().Class("tooltip__initiator").Body(
app.A().Text("For Businesses").OnClick(n.registerBusiness),
),
app.Div().Class("tooltip__item").Text("Coming soon! Join the waitlist and check https://github.com/stateless-minds/cyber-gubi for opening announcement."),
),
),
)
})
}).Else(func() app.UI {
return app.If(n.entity == "business", func() app.UI {
return app.Div().Class("menu-items").Body(
app.Div().Class("header-summary").Body(
app.Span().Class("logo").Text("cyber-gubi"),
app.Div().Class("summary-text").Body(
app.Span().Text("Business"),
),
),
app.Label().Class("menu-label").For("business-name").Text("Business Name:"),
app.Input().ID("business-name").Class("input-register").Type("text").Placeholder("Enter business name").MaxLength(22).Required(true),
app.Label().Class("menu-label").For("associate-name").Text("Associate Name:"),
app.Input().ID("associate-name").Class("input-register").Type("text").Placeholder("Enter associate name").MaxLength(22).Required(true),
app.Label().Class("menu-label").For("business-id").Text("Business ID:"),
app.Input().ID("business-id").Class("input-register").Type("text").Placeholder("Enter Business ID").Required(true),
app.Div().Class("menu-btn").Body(
app.Button().ID("submit-business-id").Class("submit").Text("Register Business").OnClick(n.submitBusinessID)),
)
})
})
}).Else(func() app.UI {
return app.If(n.isBusiness, func() app.UI {
return app.Div().Class("menu-items").Body(
app.Div().Class("header-summary").Body(
app.Span().Class("logo").Text("cyber-gubi"),
app.Div().Class("summary-text").Body(
app.Span().Text("Business"),
),
),
app.Li().Body(
app.A().Href("/associates").Text("Associates"),
),
app.Li().Body(
app.A().Href("/wallet").Text("Wallet"),
),
app.Li().Body(
app.A().Href("/payment").Text("Payment"),
),
app.Li().Body(
app.A().Href("/transactions").Text("Transactions"),
),
app.If(n.plan == Plan{}, func() app.UI {
return app.Li().Body(
app.A().Href("/plan").Text("Create Plan"),
)
}).Else(func() app.UI {
return app.Li().Body(
app.A().Href("/plan").Text("Edit Plan"),
)
}),
app.Li().Body(
app.A().Href("/clients").Text("Clients"),
),
app.Li().Body(
app.A().Href("/suppliers").Text("Suppliers"),
),
app.Li().Body(
app.A().Href("/terms-business").Text("Terms of Use"),
),
app.Li().Body(
app.A().Href("/privacy-business").Text("Privacy"),
),
app.Li().Body(
app.A().Href("/cookie-business").Text("Cookie"),
),
app.Li().Body(
app.A().Text("Delete Account").OnClick(n.deleteAccount),
),
)
}).ElseIf(n.isGovernment, func() app.UI {
return app.Div().Class("menu-items").Body(
app.Div().Class("header-summary").Body(
app.Span().Class("logo").Text("cyber-gubi"),
app.Div().Class("summary-text").Body(
app.Span().Text("Government"),
),
),
app.Li().Body(
app.A().Href("/associates").Text("Associates"),
),
app.Li().Body(
app.A().Href("/wallet").Text("Treasury"),
),
app.Li().Body(
app.A().Href("/payment").Text("Payment"),
),
app.Li().Body(
app.A().Href("/transactions").Text("Transactions"),
),
app.Li().Body(
app.A().Href("/wallets").Text("Collect Tax"),
),
app.Li().Body(
app.A().Href("/terms-government").Text("Terms of Use"),
),
app.Li().Body(
app.A().Href("/privacy").Text("Privacy"),
),
app.Li().Body(
app.A().Href("/cookie").Text("Cookie"),
),
app.Li().Body(
app.A().Text("Delete Account").OnClick(n.deleteAccount),
),
)
}).Else(func() app.UI {
return app.Div().Class("menu-items").Body(
app.Div().Class("header-summary").Body(
app.Span().Class("logo").Text("cyber-gubi"),
app.Div().Class("summary-text").Body(
app.Span().Text("Individual"),
),
),
app.Li().Body(
app.A().Href("/wallet").Text("Wallet"),
),
app.Li().Body(
app.A().Href("/payment").Text("Payment"),
),
app.Li().Body(
app.A().Href("/transactions").Text("Transactions"),
),
app.Li().Body(
app.A().Href("/subscriptions").Text("Subscriptions"),
),
app.Li().Body(
app.A().Href("/terms").Text("Terms of Use"),
),
app.Li().Body(
app.A().Href("/privacy").Text("Privacy"),
),
app.Li().Body(
app.A().Href("/cookie").Text("Cookie"),
),
app.Li().Body(
app.A().Text("Delete Account").OnClick(n.deleteAccount),
),
)
})
}),
),
),
)
}