feat: timezone locales field
This commit is contained in:
parent
074dbabbba
commit
94af408d8e
3 changed files with 76 additions and 4 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import * as ct from 'countries-and-timezones'
|
||||||
import * as R from 'ramda'
|
import * as R from 'ramda'
|
||||||
import * as Yup from 'yup'
|
import * as Yup from 'yup'
|
||||||
|
|
||||||
|
|
@ -36,6 +37,55 @@ const allFields = (getData, onChange, auxElements = []) => {
|
||||||
const currencyData = getData(['currencies'])
|
const currencyData = getData(['currencies'])
|
||||||
const languageData = getData(['languages'])
|
const languageData = getData(['languages'])
|
||||||
const cryptoData = getData(['cryptoCurrencies'])
|
const cryptoData = getData(['cryptoCurrencies'])
|
||||||
|
const timezonesData = R.values(ct.getAllTimezones())
|
||||||
|
|
||||||
|
const possibleUTCDSTPairs = R.map(
|
||||||
|
it => ({
|
||||||
|
utcOffset: it.utcOffset,
|
||||||
|
dstOffset: it.dstOffset,
|
||||||
|
utcOffsetStr: it.utcOffsetStr,
|
||||||
|
dstOffsetStr: it.dstOffsetStr
|
||||||
|
}),
|
||||||
|
R.uniqBy(
|
||||||
|
it => [it.utcOffset, it.dstOffset, it.utcOffsetStr, it.dstOffsetStr],
|
||||||
|
timezonesData
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
const finalTimezones = R.sort(
|
||||||
|
R.ascend(R.prop('utcOffset')),
|
||||||
|
R.map(
|
||||||
|
it => ({
|
||||||
|
utcOffset: it.utcOffset,
|
||||||
|
dstOffset: it.dstOffset,
|
||||||
|
utcOffsetStr: it.utcOffsetStr,
|
||||||
|
dstOffsetStr: it.dstOffsetStr,
|
||||||
|
cities: R.map(
|
||||||
|
ite => ite.name,
|
||||||
|
R.filter(
|
||||||
|
itx =>
|
||||||
|
R.eqProps('utcOffset', it, itx) &&
|
||||||
|
R.eqProps('dstOffset', it, itx),
|
||||||
|
timezonesData
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
possibleUTCDSTPairs
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
const buildLabel = tz => {
|
||||||
|
return `UTC ${tz.utcOffsetStr}${
|
||||||
|
tz.utcOffset !== tz.dstOffset ? ' (Daylight Saving Time)' : ''
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const tzLabels = R.map(
|
||||||
|
it => ({ label: buildLabel(it), code: it }),
|
||||||
|
finalTimezones
|
||||||
|
)
|
||||||
|
|
||||||
|
console.log(tzLabels)
|
||||||
|
|
||||||
const findSuggestion = it => {
|
const findSuggestion = it => {
|
||||||
const machine = R.find(R.propEq('deviceId', it.machine))(machineData)
|
const machine = R.find(R.propEq('deviceId', it.machine))(machineData)
|
||||||
|
|
@ -95,7 +145,7 @@ const allFields = (getData, onChange, auxElements = []) => {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'cryptoCurrencies',
|
name: 'cryptoCurrencies',
|
||||||
width: 290,
|
width: 220,
|
||||||
size: 'sm',
|
size: 'sm',
|
||||||
view: displayCodeArray(cryptoData),
|
view: displayCodeArray(cryptoData),
|
||||||
input: Autocomplete,
|
input: Autocomplete,
|
||||||
|
|
@ -107,6 +157,18 @@ const allFields = (getData, onChange, auxElements = []) => {
|
||||||
optionsLimit: null,
|
optionsLimit: null,
|
||||||
onChange
|
onChange
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'timezone',
|
||||||
|
width: 220,
|
||||||
|
size: 'sm',
|
||||||
|
view: getView(tzLabels, 'label'),
|
||||||
|
input: Autocomplete,
|
||||||
|
inputProps: {
|
||||||
|
options: tzLabels,
|
||||||
|
valueProp: 'code',
|
||||||
|
labelProp: 'label'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -116,7 +178,7 @@ const mainFields = (auxData, configureCoin) => {
|
||||||
|
|
||||||
return getFields(
|
return getFields(
|
||||||
getData,
|
getData,
|
||||||
['country', 'fiatCurrency', 'languages', 'cryptoCurrencies'],
|
['country', 'fiatCurrency', 'languages', 'cryptoCurrencies', 'timezone'],
|
||||||
configureCoin
|
configureCoin
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -147,7 +209,10 @@ const LocaleSchema = Yup.object().shape({
|
||||||
cryptoCurrencies: Yup.array()
|
cryptoCurrencies: Yup.array()
|
||||||
.label('Crypto Currencies')
|
.label('Crypto Currencies')
|
||||||
.required()
|
.required()
|
||||||
.min(1)
|
.min(1),
|
||||||
|
timezone: Yup.object()
|
||||||
|
.label('Timezone')
|
||||||
|
.required()
|
||||||
})
|
})
|
||||||
|
|
||||||
const OverridesSchema = Yup.object().shape({
|
const OverridesSchema = Yup.object().shape({
|
||||||
|
|
@ -171,7 +236,8 @@ const localeDefaults = {
|
||||||
country: '',
|
country: '',
|
||||||
fiatCurrency: '',
|
fiatCurrency: '',
|
||||||
languages: [],
|
languages: [],
|
||||||
cryptoCurrencies: []
|
cryptoCurrencies: [],
|
||||||
|
timezone: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
const overridesDefaults = {
|
const overridesDefaults = {
|
||||||
|
|
|
||||||
5
package-lock.json
generated
5
package-lock.json
generated
|
|
@ -6115,6 +6115,11 @@
|
||||||
"vary": "^1"
|
"vary": "^1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"countries-and-timezones": {
|
||||||
|
"version": "2.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/countries-and-timezones/-/countries-and-timezones-2.4.0.tgz",
|
||||||
|
"integrity": "sha512-h6k9zgw99k8fjon5cO94k8Aslyj0fM+S4hfTyJ6sbSjyOO9lu5/wcOXLrhc1cGUoHCrnx56WYSNEasSKqSGlJw=="
|
||||||
|
},
|
||||||
"crc": {
|
"crc": {
|
||||||
"version": "3.5.0",
|
"version": "3.5.0",
|
||||||
"resolved": "https://registry.npmjs.org/crc/-/crc-3.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/crc/-/crc-3.5.0.tgz",
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
"console-log-level": "^1.4.0",
|
"console-log-level": "^1.4.0",
|
||||||
"cookie-parser": "^1.4.3",
|
"cookie-parser": "^1.4.3",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
|
"countries-and-timezones": "^2.4.0",
|
||||||
"dataloader": "^2.0.0",
|
"dataloader": "^2.0.0",
|
||||||
"ed25519": "git+https://github.com/lamassu/ed25519#3140c985fee9828ce6707202f9f7d55cb1f0b46d",
|
"ed25519": "git+https://github.com/lamassu/ed25519#3140c985fee9828ce6707202f9f7d55cb1f0b46d",
|
||||||
"ethereumjs-tx": "^1.3.3",
|
"ethereumjs-tx": "^1.3.3",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue