@@ -5,7 +5,7 @@ import { saveAs } from 'file-saver'
5
5
6
6
import { withOwner , WithOwnerProps } from '~lib/pageWrappers'
7
7
import { CurrentOwner , useCompany , useModals } from '~lib/hooks'
8
- import { IconButton } from '~ui/core'
8
+ import { Box , Button , Checkbox , Icon , IconButton } from '~ui/core'
9
9
import { Edit , Trash , Download } from '~ui/svg'
10
10
import { OwnerApp , BackLink } from '~ui/layouts/OwnerApp'
11
11
import { ActionList } from '~ui/blocks/ActionList'
@@ -18,6 +18,9 @@ import { QrInfoModal } from '~ui/modals/QrInfoModal'
18
18
import { AreaRes , CompanyRes } from '~lib/api'
19
19
import { decrypt } from '~lib/crypto'
20
20
import { sortAreas } from '~lib/interactors'
21
+ import { Form , Formik } from 'formik'
22
+ import styled from '@emotion/styled'
23
+ import { css } from '@emotion/react'
21
24
22
25
const AreasIndexPage : React . FC < WithOwnerProps > = ( { owner } ) => {
23
26
const { query } = useRouter ( )
@@ -69,6 +72,12 @@ const AreasIndexPage: React.FC<WithOwnerProps> = ({ owner }) => {
69
72
}
70
73
}
71
74
75
+ const areas = sortAreas ( company ?. areas )
76
+
77
+ const handleSubmit = async ( values , _bag ) => {
78
+ console . log ( values )
79
+ }
80
+
72
81
return (
73
82
< OwnerApp title = { `${ company ?. name ?? '' } – Bereiche` } >
74
83
< BackLink
@@ -83,44 +92,82 @@ const AreasIndexPage: React.FC<WithOwnerProps> = ({ owner }) => {
83
92
title = "Bereich hinzufügen..."
84
93
onClick = { ( ) => openModal ( 'data' , { companyId : companyId } ) }
85
94
/>
86
- { sortAreas ( company ?. areas ) . map ( ( area ) => (
87
- < ActionCard
88
- key = { area . id }
89
- href = "/business/company/[companyId]/area/[areaId]"
90
- as = { `/business/company/${ companyId } /area/${ area . id } ` }
91
- >
92
- < ActionCard . Main title = { area . name } />
93
- < ActionCard . Actions >
94
- < IconButton
95
- icon = { Download }
96
- color = "bluegrey.700"
97
- onClick = { handleDownload ( area ) }
98
- title = "QR-Code"
99
- />
100
- < IconButton
101
- icon = { Edit }
102
- color = "yellow.500"
103
- onClick = { ( ) =>
104
- openModal ( 'data' , {
105
- type : 'edit' ,
106
- areaId : area . id ,
107
- name : area . name ,
108
- testExemption : area . testExemption ,
109
- } )
110
- }
111
- title = "Ändern"
112
- />
113
- < IconButton
114
- icon = { Trash }
115
- color = "red.500"
116
- onClick = { ( ) => openModal ( 'delete' ) }
117
- />
118
- </ ActionCard . Actions >
119
- </ ActionCard >
120
- ) ) }
95
+
96
+ < Formik
97
+ initialValues = { Object . assign (
98
+ { } ,
99
+ ...areas . map ( ( area ) => ( { [ `selected-${ area . id } ` ] : false } ) )
100
+ ) }
101
+ onSubmit = { handleSubmit }
102
+ >
103
+ < Form >
104
+ { areas . map ( ( area ) => (
105
+ < ActionCard
106
+ key = { area . id }
107
+ href = "/business/company/[companyId]/area/[areaId]"
108
+ as = { `/business/company/${ companyId } /area/${ area . id } ` }
109
+ >
110
+ < ExpandArea >
111
+ < Checkbox name = { `selected-${ area . id } ` } label = { area . name } />
112
+ </ ExpandArea >
113
+ < ActionCard . Actions >
114
+ < IconButton
115
+ icon = { Download }
116
+ color = "bluegrey.700"
117
+ onClick = { handleDownload ( area ) }
118
+ title = "QR-Code"
119
+ />
120
+ < IconButton
121
+ icon = { Edit }
122
+ color = "yellow.500"
123
+ onClick = { ( ) =>
124
+ openModal ( 'data' , {
125
+ type : 'edit' ,
126
+ areaId : area . id ,
127
+ name : area . name ,
128
+ testExemption : area . testExemption ,
129
+ } )
130
+ }
131
+ title = "Ändern"
132
+ />
133
+ < IconButton
134
+ icon = { Trash }
135
+ color = "red.500"
136
+ onClick = { ( ) => openModal ( 'delete' ) }
137
+ />
138
+ </ ActionCard . Actions >
139
+ </ ActionCard >
140
+ ) ) }
141
+ < Box height = { 4 } />
142
+ < Button type = "submit" >
143
+ < DeleteAllContent >
144
+ < Icon size = { 4 } color = "red.500" icon = { Trash } />
145
+ < ButtonText > Ausgewählte Bereiche löschen</ ButtonText >
146
+ </ DeleteAllContent >
147
+ </ Button >
148
+ </ Form >
149
+ </ Formik >
121
150
</ ActionList >
122
151
</ OwnerApp >
123
152
)
124
153
}
125
154
155
+ const ExpandArea = styled ( 'div' ) (
156
+ css ( {
157
+ flexGrow : 1 ,
158
+ } )
159
+ )
160
+
161
+ const DeleteAllContent = styled ( 'div' ) (
162
+ css ( {
163
+ display : 'flex' ,
164
+ } )
165
+ )
166
+
167
+ const ButtonText = styled ( 'div' ) (
168
+ css ( {
169
+ marginLeft : '0.5rem' ,
170
+ } )
171
+ )
172
+
126
173
export default withOwner ( ) ( AreasIndexPage )
0 commit comments