Skip to content

Commit 875e8c3

Browse files
Andrewjeskaseambot
andauthored
Create Climate Setting Schedule - Timezone Picker (#468)
Co-authored-by: Seam Bot <[email protected]>
1 parent cf01c27 commit 875e8c3

5 files changed

+135
-7
lines changed

Diff for: src/lib/ui/ClimateSettingForm/ClimateSettingScheduleForm.tsx

+36-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import { useState } from 'react'
33
import { useForm } from 'react-hook-form'
44
import type { ClimateSetting } from 'seamapi'
55

6+
import { getBrowserTimezone } from 'lib/dates.js'
67
import { ClimateSettingScheduleFormDeviceSelect } from 'lib/ui/ClimateSettingForm/ClimateSettingScheduleFormDeviceSelect.js'
78
import { ClimateSettingScheduleFormNameAndSchedule } from 'lib/ui/ClimateSettingForm/ClimateSettingScheduleFormNameAndSchedule.js'
9+
import { ClimateSettingScheduleFormTimezonePicker } from 'lib/ui/ClimateSettingForm/ClimateSettingScheduleFormTimezonePicker.js'
810

911
export interface ClimateSettingScheduleFormSubmitData {
1012
name: string
@@ -22,6 +24,14 @@ export interface ClimateSettingScheduleFormProps {
2224
onSubmit: (data: ClimateSettingScheduleFormSubmitData) => void
2325
}
2426

27+
export interface ClimateSettingScheduleFormFields {
28+
name: string
29+
deviceId: string
30+
startDate: string
31+
endDate: string
32+
timezone: string
33+
}
34+
2535
export function ClimateSettingScheduleForm({
2636
className,
2737
...props
@@ -38,9 +48,18 @@ export function ClimateSettingScheduleForm({
3848
function Content({
3949
onBack,
4050
}: Omit<ClimateSettingScheduleFormProps, 'className'>): JSX.Element {
41-
const { control, watch } = useForm()
51+
const { control, watch } = useForm({
52+
defaultValues: {
53+
deviceId: '',
54+
name: '',
55+
startDate: '',
56+
endDate: '',
57+
timezone: getBrowserTimezone(),
58+
},
59+
})
4260

43-
const deviceId = watch('deviceId', null)
61+
const deviceId = watch('deviceId')
62+
const timezone = watch('timezone')
4463

4564
const [page, setPage] = useState<
4665
| 'device_select'
@@ -76,6 +95,21 @@ function Content({
7695
onNext={() => {
7796
setPage('climate_setting')
7897
}}
98+
onChangeTimezone={() => {
99+
setPage('timezone_select')
100+
}}
101+
timezone={timezone}
102+
/>
103+
)
104+
}
105+
106+
if (page === 'timezone_select') {
107+
return (
108+
<ClimateSettingScheduleFormTimezonePicker
109+
control={control}
110+
onClose={() => {
111+
setPage('name_and_schedule')
112+
}}
79113
/>
80114
)
81115
}

Diff for: src/lib/ui/ClimateSettingForm/ClimateSettingScheduleFormDeviceSelect.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { type Control, Controller, type FieldValues } from 'react-hook-form'
1+
import { type Control, Controller } from 'react-hook-form'
22

3+
import type { ClimateSettingScheduleFormFields } from 'lib/ui/ClimateSettingForm/ClimateSettingScheduleForm.js'
34
import { ContentHeader } from 'lib/ui/layout/ContentHeader.js'
45
import { ThermostatSelect } from 'lib/ui/thermostat/ThermostatSelect.js'
56

67
interface ClimateSettingScheduleFormDeviceSelectProps {
78
title: string
8-
control: Control<FieldValues>
9+
control: Control<ClimateSettingScheduleFormFields>
910
onSelect: () => void
1011
onBack: (() => void) | undefined
1112
}

Diff for: src/lib/ui/ClimateSettingForm/ClimateSettingScheduleFormNameAndSchedule.tsx

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import { type Control, Controller, type FieldValues } from 'react-hook-form'
1+
import { type Control, Controller } from 'react-hook-form'
22

3+
import { getTimezoneLabel } from 'lib/dates.js'
4+
import { ChevronRightIcon } from 'lib/icons/ChevronRight.js'
35
import { useDevice } from 'lib/seam/devices/use-device.js'
46
import { Button } from 'lib/ui/Button.js'
7+
import type { ClimateSettingScheduleFormFields } from 'lib/ui/ClimateSettingForm/ClimateSettingScheduleForm.js'
58
import { DateTimePicker } from 'lib/ui/DateTimePicker/DateTimePicker.js'
69
import { FormField } from 'lib/ui/FormField.js'
710
import { InputLabel } from 'lib/ui/InputLabel.js'
@@ -10,20 +13,24 @@ import { TextField } from 'lib/ui/TextField/TextField.js'
1013

1114
interface ClimateSettingScheduleFormNameAndScheduleProps {
1215
title: string
13-
control: Control<FieldValues>
16+
control: Control<ClimateSettingScheduleFormFields>
1417
deviceId: string
18+
timezone: string
1519
onBack: () => void
1620
onCancel: (() => void) | undefined
1721
onNext: () => void
22+
onChangeTimezone: () => void
1823
}
1924

2025
export function ClimateSettingScheduleFormNameAndSchedule({
2126
title,
27+
control,
2228
deviceId,
29+
timezone,
2330
onBack,
2431
onCancel,
2532
onNext,
26-
control,
33+
onChangeTimezone,
2734
}: ClimateSettingScheduleFormNameAndScheduleProps): JSX.Element {
2835
const { device } = useDevice({
2936
device_id: deviceId,
@@ -58,8 +65,16 @@ export function ClimateSettingScheduleFormNameAndSchedule({
5865
}}
5966
/>
6067
</FormField>
68+
6169
<FormField>
6270
<InputLabel>{t.startTimeLabel}</InputLabel>
71+
<div className='seam-timezone'>
72+
<span className='seam-label'>{t.selectedTimezoneLabel}</span>
73+
<span className='seam-selected' onClick={onChangeTimezone}>
74+
{getTimezoneLabel(timezone)}
75+
<ChevronRightIcon />
76+
</span>
77+
</div>
6378
<Controller
6479
name='startDate'
6580
control={control}
@@ -101,4 +116,5 @@ const t = {
101116
cancel: 'Cancel',
102117
save: 'Save',
103118
next: 'Next',
119+
selectedTimezoneLabel: 'All times in',
104120
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { useState } from 'react'
2+
import { type Control, Controller } from 'react-hook-form'
3+
4+
import type { ClimateSettingScheduleFormFields } from 'lib/ui/ClimateSettingForm/ClimateSettingScheduleForm.js'
5+
import { ContentHeader } from 'lib/ui/layout/ContentHeader.js'
6+
import { TimezonePicker } from 'lib/ui/TimezonePicker/TimezonePicker.js'
7+
8+
interface ClimateSettingScheduleFormTimezonePickerProps {
9+
control: Control<ClimateSettingScheduleFormFields>
10+
onClose: () => void
11+
}
12+
13+
export function ClimateSettingScheduleFormTimezonePicker({
14+
control,
15+
onClose,
16+
}: ClimateSettingScheduleFormTimezonePickerProps): JSX.Element {
17+
const [title, setTitle] = useState(t.titleAuto)
18+
19+
return (
20+
<>
21+
<ContentHeader title={title} onBack={onClose} />
22+
<div className='seam-main'>
23+
<Controller
24+
name='timezone'
25+
control={control}
26+
render={({ field }) => (
27+
<TimezonePicker
28+
{...field}
29+
onManualTimezoneSelected={(manualTimezoneSelected) => {
30+
setTitle(manualTimezoneSelected ? t.titleManual : t.titleAuto)
31+
}}
32+
/>
33+
)}
34+
/>
35+
</div>
36+
</>
37+
)
38+
}
39+
40+
const t = {
41+
titleAuto: 'Time Zone (automatic)',
42+
titleManual: 'Time Zone (manual)',
43+
}

Diff for: src/styles/_climate-setting-schedule-form.scss

+34
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
@mixin all {
44
.seam-climate-setting-schedule-form {
55
@include main;
6+
@include name-and-schedule;
67
}
78
}
89

@@ -21,3 +22,36 @@
2122
}
2223
}
2324
}
25+
26+
@mixin name-and-schedule {
27+
.seam-climate-setting-schedule-form-name-and-schedule {
28+
.seam-timezone {
29+
display: flex;
30+
align-items: center;
31+
font-size: 14px;
32+
margin-top: -6px;
33+
margin-bottom: 4px;
34+
35+
.seam-label {
36+
color: colors.$text-gray-2;
37+
margin-right: 4px;
38+
}
39+
40+
.seam-selected {
41+
color: colors.$primary;
42+
cursor: pointer;
43+
display: flex;
44+
align-items: center;
45+
46+
svg {
47+
scale: 0.6667;
48+
transform: translate(-6px, 2px);
49+
50+
* {
51+
fill: colors.$primary;
52+
}
53+
}
54+
}
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)