Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: andreas-unleash <andreas@getunleash.ai> 1st Iteration = Show the user the timezone and UTC offset <!-- Thanks for creating a PR! To make it easier for reviewers and everyone else to understand what your changes relate to, please add some relevant content to the headings below. Feel free to ignore or delete sections that you don't think are relevant. Thank you! ❤️ --> ## About the changes <!-- Describe the changes introduced. What are they and why are they being introduced? Feel free to also add screenshots or steps to view the changes if they're visual. --> <!-- Does it close an issue? Multipl ![Screenshot 2023-01-27 at 09 46 27](https://user-images.githubusercontent.com/104830839/215034585-d6abe3be-7a13-414c-ada4-b06231ab05a7.png) e? --> Closes # [issue 1-568](https://linear.app/unleash/issue/1-568/show-the-timezone-for-the-currenttime-constraint) <!-- (For internal contributors): Does it relate to an issue on public roadmap? --> <!-- Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item: # --> ### Important files <!-- PRs can contain a lot of changes, but not all changes are equally important. Where should a reviewer start looking to get an overview of the changes? Are any files particularly important? --> ## Discussion points <!-- Anything about the PR you'd like to discuss before it gets merged? Got any questions or doubts? --> --------- Signed-off-by: andreas-unleash <andreas@getunleash.ai> Co-authored-by: Thomas Heartman <thomas@getunleash.ai>
- Loading branch information
1 parent
8126049
commit 751b714
Showing
5 changed files
with
150 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 7 additions & 14 deletions
21
...ntAccordionEdit/ConstraintAccordionEditBody/ConstraintFormHeader/ConstraintFormHeader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,15 @@ | ||
import { makeStyles } from 'tss-react/mui'; | ||
import React from 'react'; | ||
import { styled } from '@mui/material'; | ||
|
||
const useStyles = makeStyles()(theme => ({ | ||
header: { | ||
fontSize: theme.fontSizes.bodySize, | ||
fontWeight: 'normal', | ||
marginTop: '1rem', | ||
marginBottom: '0.25rem', | ||
}, | ||
const StyledHeader = styled('h3')(({ theme }) => ({ | ||
fontSize: theme.fontSizes.bodySize, | ||
fontWeight: theme.typography.fontWeightMedium, | ||
marginTop: theme.spacing(2), | ||
marginBottom: theme.spacing(0.5), | ||
})); | ||
|
||
export const ConstraintFormHeader: React.FC< | ||
React.HTMLAttributes<HTMLDivElement> | ||
> = ({ children, ...rest }) => { | ||
const { classes: styles } = useStyles(); | ||
return ( | ||
<h3 {...rest} className={styles.header}> | ||
{children} | ||
</h3> | ||
); | ||
return <StyledHeader {...rest}>{children}</StyledHeader>; | ||
}; |
73 changes: 55 additions & 18 deletions
73
...n/ConstraintAccordionEdit/ConstraintAccordionEditBody/DateSingleValue/DateSingleValue.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,79 @@ | ||
import { ConstraintFormHeader } from '../ConstraintFormHeader/ConstraintFormHeader'; | ||
import Input from 'component/common/Input/Input'; | ||
import { parseDateValue, parseValidDate } from 'component/common/util'; | ||
|
||
import { useMemo, useState } from 'react'; | ||
import { styled } from '@mui/material'; | ||
import TimezoneCountries from 'countries-and-timezones'; | ||
|
||
interface IDateSingleValueProps { | ||
setValue: (value: string) => void; | ||
value?: string; | ||
error: string; | ||
setError: React.Dispatch<React.SetStateAction<string>>; | ||
} | ||
|
||
const StyledWrapper = styled('div')(({ theme }) => ({ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
marginBottom: theme.spacing(1), | ||
alignItems: 'center', | ||
gap: theme.spacing(1), | ||
})); | ||
|
||
export const DateSingleValue = ({ | ||
setValue, | ||
value, | ||
error, | ||
setError, | ||
}: IDateSingleValueProps) => { | ||
const timezones = Object.values( | ||
TimezoneCountries.getAllTimezones({ deprecated: false }) | ||
).map(timezone => ({ | ||
key: timezone.name, | ||
label: `${timezone.name}`, | ||
utcOffset: timezone.utcOffsetStr, | ||
})); | ||
const { timeZone: localTimezoneName } = | ||
Intl.DateTimeFormat().resolvedOptions(); | ||
const [pickedDate, setPickedDate] = useState(value || ''); | ||
|
||
const timezoneText = useMemo<string>(() => { | ||
const localTimezone = timezones.find(t => t.key === localTimezoneName); | ||
if (localTimezone != null) { | ||
return `${localTimezone.key} (UTC ${localTimezone.utcOffset})`; | ||
} else { | ||
return 'The time shown is in your local time zone according to your browser.'; | ||
} | ||
}, [timezones, localTimezoneName]); | ||
|
||
if (!value) return null; | ||
|
||
return ( | ||
<> | ||
<ConstraintFormHeader>Select a date</ConstraintFormHeader> | ||
<Input | ||
id="date" | ||
label="Date" | ||
type="datetime-local" | ||
value={parseDateValue(value)} | ||
onChange={e => { | ||
setError(''); | ||
const parsedDate = parseValidDate(e.target.value); | ||
const dateString = parsedDate?.toISOString(); | ||
dateString && setValue(dateString); | ||
}} | ||
InputLabelProps={{ | ||
shrink: true, | ||
}} | ||
error={Boolean(error)} | ||
errorText={error} | ||
required | ||
/> | ||
<StyledWrapper> | ||
<Input | ||
id="date" | ||
label="Date" | ||
type="datetime-local" | ||
value={parseDateValue(pickedDate)} | ||
onChange={e => { | ||
setError(''); | ||
const parsedDate = parseValidDate(e.target.value); | ||
const dateString = parsedDate?.toISOString(); | ||
dateString && setPickedDate(dateString); | ||
dateString && setValue(dateString); | ||
}} | ||
InputLabelProps={{ | ||
shrink: true, | ||
}} | ||
error={Boolean(error)} | ||
errorText={error} | ||
required | ||
/> | ||
<p>{timezoneText}</p> | ||
</StyledWrapper> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters