Skip to content

Commit 693dc46

Browse files
committed
[#156] As a user I want to delete more then one…
…"Bereich" at once. closes #156
1 parent 9fba983 commit 693dc46

File tree

3 files changed

+126
-57
lines changed

3 files changed

+126
-57
lines changed

next-env.d.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/types/global" />
3+
/// <reference types="next/image-types/global" />
34

4-
declare module '*.svg' {
5-
const value: React.FC<JSX.IntrinsicElements['svg']>
6-
export default value
7-
}
5+
// NOTE: This file should not be edited
6+
// see https://nextjs.org/docs/basic-features/typescript for more information.

pages/business/company/[companyId]/area/index.tsx

+83-36
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { saveAs } from 'file-saver'
55

66
import { withOwner, WithOwnerProps } from '~lib/pageWrappers'
77
import { CurrentOwner, useCompany, useModals } from '~lib/hooks'
8-
import { IconButton } from '~ui/core'
8+
import { Box, Button, Checkbox, Icon, IconButton } from '~ui/core'
99
import { Edit, Trash, Download } from '~ui/svg'
1010
import { OwnerApp, BackLink } from '~ui/layouts/OwnerApp'
1111
import { ActionList } from '~ui/blocks/ActionList'
@@ -18,6 +18,9 @@ import { QrInfoModal } from '~ui/modals/QrInfoModal'
1818
import { AreaRes, CompanyRes } from '~lib/api'
1919
import { decrypt } from '~lib/crypto'
2020
import { sortAreas } from '~lib/interactors'
21+
import { Form, Formik } from 'formik'
22+
import styled from '@emotion/styled'
23+
import { css } from '@emotion/react'
2124

2225
const AreasIndexPage: React.FC<WithOwnerProps> = ({ owner }) => {
2326
const { query } = useRouter()
@@ -69,6 +72,12 @@ const AreasIndexPage: React.FC<WithOwnerProps> = ({ owner }) => {
6972
}
7073
}
7174

75+
const areas = sortAreas(company?.areas)
76+
77+
const handleSubmit = async (values, _bag) => {
78+
console.log(values)
79+
}
80+
7281
return (
7382
<OwnerApp title={`${company?.name ?? ''} – Bereiche`}>
7483
<BackLink
@@ -83,44 +92,82 @@ const AreasIndexPage: React.FC<WithOwnerProps> = ({ owner }) => {
8392
title="Bereich hinzufügen..."
8493
onClick={() => openModal('data', { companyId: companyId })}
8594
/>
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>
121150
</ActionList>
122151
</OwnerApp>
123152
)
124153
}
125154

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+
126173
export default withOwner()(AreasIndexPage)

ui/blocks/ActionCard.tsx

+40-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react'
22
import Link from 'next/link'
3+
import { useRouter } from 'next/router'
34
import { Card, SRText, Row, Text, Box, Icon } from '~ui/core'
45

56
interface Props {
@@ -18,32 +19,54 @@ interface Composition {
1819
type AreaCardCmps = React.FC<Props> & Composition
1920

2021
export const ActionCard: AreaCardCmps = ({ href, as, onClick, children }) => {
22+
const router = useRouter()
23+
24+
const isTargetOrNonInteractiveElement = (event: React.MouseEvent) => {
25+
if (event.target == event.currentTarget) {
26+
return true
27+
}
28+
29+
let parentNode = event.target as HTMLElement
30+
let isInteractive = false
31+
32+
while (!isInteractive && parentNode && parentNode != event.currentTarget) {
33+
if (
34+
['A', 'INPUT', 'BUTTON'].includes(parentNode.nodeName) ||
35+
parentNode.hasAttribute('href') ||
36+
parentNode.hasAttribute('onClick') ||
37+
parentNode.hasAttribute('for')
38+
) {
39+
isInteractive = true
40+
}
41+
parentNode = parentNode.parentNode as HTMLElement
42+
}
43+
44+
return !isInteractive
45+
}
46+
47+
const navigateToHref = (event) => {
48+
if (as && isTargetOrNonInteractiveElement(event)) {
49+
event.preventDefault()
50+
router.push(as)
51+
}
52+
}
53+
2154
return (
2255
<Card
23-
css={{ position: 'relative', textAlign: 'left' }}
56+
css={{ position: 'relative', textAlign: 'left', cursor: 'pointer' }}
2457
as={onClick ? 'button' : 'div'}
25-
onClick={onClick}
58+
onClick={onClick ? onClick : navigateToHref}
2659
>
2760
<>
2861
<Row flexWrap="wrap" alignItems="center" px={4} py={2}>
2962
{children}
3063
</Row>
3164
{href && (
32-
<Link href={href} as={as}>
33-
<a
34-
css={{
35-
position: 'absolute',
36-
top: 0,
37-
left: 0,
38-
right: 0,
39-
bottom: 0,
40-
zIndex: 1,
41-
cursor: 'pointer',
42-
}}
43-
>
44-
<SRText>Zur Seite navigieren</SRText>
45-
</a>
46-
</Link>
65+
<SRText>
66+
<Link href={href} as={as}>
67+
Zur Seite navigieren
68+
</Link>
69+
</SRText>
4770
)}
4871
</>
4972
</Card>

0 commit comments

Comments
 (0)