Skip to content

Commit a154dff

Browse files
committed
Create initial out-of-office form
1 parent 5e75a27 commit a154dff

File tree

2 files changed

+80
-3
lines changed

2 files changed

+80
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import React, { Fragment } from 'react'
2+
3+
import { useTranslation } from 'employee-frontend/state/i18n'
4+
import { Result } from 'lib-common/api'
5+
import { localDateRange } from 'lib-common/form/fields'
6+
import { object, required } from 'lib-common/form/form'
7+
import { useForm, useFormFields } from 'lib-common/form/hooks'
8+
import { StateOf } from 'lib-common/form/types'
9+
import { AsyncButton } from 'lib-components/atoms/buttons/AsyncButton'
10+
import { Button } from 'lib-components/atoms/buttons/Button'
11+
import ButtonContainer from 'lib-components/layout/ButtonContainer'
12+
import { DateRangePickerF } from 'lib-components/molecules/date-picker/DateRangePicker'
13+
import { Gap } from 'lib-components/white-space'
14+
15+
const outOfOfficeForm = object({ period: required(localDateRange()) })
16+
17+
function initialFormState(): StateOf<typeof outOfOfficeForm> {
18+
return { period: localDateRange.empty() }
19+
}
20+
21+
export interface OutOfOfficeEditorProps {
22+
onCancel: () => void
23+
}
24+
25+
export default React.memo(function OutOfOfficeEditor({
26+
onCancel
27+
}: OutOfOfficeEditorProps) {
28+
const { i18n, lang } = useTranslation()
29+
30+
const form = useForm(outOfOfficeForm, initialFormState, {
31+
...i18n.validationErrors,
32+
...i18n.components.datePicker.validationErrors
33+
})
34+
35+
const { period } = useFormFields(form)
36+
37+
return (
38+
<Fragment>
39+
<DateRangePickerF bind={period} locale={lang} hideErrorsBeforeTouched />
40+
<Gap size="X4L" />
41+
<ButtonContainer>
42+
<AsyncButton
43+
text={i18n.common.save}
44+
primary
45+
disabled={!form.isValid()}
46+
onClick={function (): void | Promise<Result<unknown>> {
47+
throw new Error('Function not implemented.')
48+
}}
49+
onSuccess={function (): void {
50+
throw new Error('Function not implemented.')
51+
}}
52+
/>
53+
<Gap size="xs" horizontal />
54+
<Button
55+
text={i18n.common.cancel}
56+
appearance="inline"
57+
onClick={onCancel}
58+
/>
59+
</ButtonContainer>
60+
</Fragment>
61+
)
62+
})

frontend/src/employee-frontend/components/out-of-office/OutOfOfficePage.tsx

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
import React from 'react'
1+
import React, { Fragment, useState } from 'react'
22

33
import { useTranslation } from 'employee-frontend/state/i18n'
44
import { Button } from 'lib-components/atoms/buttons/Button'
55
import Container, { ContentArea } from 'lib-components/layout/Container'
66
import { H1, Label, P } from 'lib-components/typography'
77
import { Gap } from 'lib-components/white-space'
88

9+
import OutOfOfficeEditor from './OutOfOfficeEditor'
10+
911
export default React.memo(function OutOfOfficePage() {
1012
const { i18n } = useTranslation()
13+
const [isEditing, setIsEditing] = useState(false)
1114

1215
return (
1316
<Container>
@@ -16,8 +19,20 @@ export default React.memo(function OutOfOfficePage() {
1619
<P>{i18n.outOfOffice.description}</P>
1720
<Gap size="m" />
1821
<Label>{i18n.outOfOffice.header}</Label>
19-
<P>{i18n.outOfOffice.noFutureOutOfOffice}</P>
20-
<Button text={i18n.outOfOffice.addOutOfOffice} primary />
22+
<Gap size="s" />
23+
{isEditing ? (
24+
<OutOfOfficeEditor onCancel={() => setIsEditing(false)} />
25+
) : (
26+
<Fragment>
27+
<div>{i18n.outOfOffice.noFutureOutOfOffice}</div>
28+
<Gap size="m" />
29+
<Button
30+
text={i18n.outOfOffice.addOutOfOffice}
31+
primary
32+
onClick={() => setIsEditing(true)}
33+
/>
34+
</Fragment>
35+
)}
2136
</ContentArea>
2237
</Container>
2338
)

0 commit comments

Comments
 (0)