From 8853f1fd2089df55566309ac093d3b2f3d906a9c Mon Sep 17 00:00:00 2001 From: Liordino Neto Date: Fri, 11 Sep 2020 00:10:53 -0300 Subject: [PATCH] feat: added an alert to confirm fiat currency changes on locales --- .../src/pages/Locales/Locales.js | 64 +++++++++++++++++-- .../src/pages/Locales/Locales.styles.js | 12 ++++ 2 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 new-lamassu-admin/src/pages/Locales/Locales.styles.js diff --git a/new-lamassu-admin/src/pages/Locales/Locales.js b/new-lamassu-admin/src/pages/Locales/Locales.js index 991c313e..616ab86d 100644 --- a/new-lamassu-admin/src/pages/Locales/Locales.js +++ b/new-lamassu-admin/src/pages/Locales/Locales.js @@ -1,13 +1,18 @@ import { useQuery, useMutation } from '@apollo/react-hooks' +import { makeStyles } from '@material-ui/core/styles' import gql from 'graphql-tag' import * as R from 'ramda' -import React from 'react' +import React, { useState } from 'react' +import Modal from 'src/components/Modal' +import { Link } from 'src/components/buttons' import { Table as EditableTable } from 'src/components/editableTable' import Section from 'src/components/layout/Section' import TitleSection from 'src/components/layout/TitleSection' +import { P } from 'src/components/typography' import { fromNamespace, toNamespace } from 'src/utils/config' +import { styles } from './Locales.styles' import { mainFields, overrides, @@ -17,6 +22,8 @@ import { overridesDefaults } from './helper' +const useStyles = makeStyles(styles) + const GET_DATA = gql` query getData { config @@ -49,20 +56,62 @@ const SAVE_CONFIG = gql` } ` +const FiatCurrencyChangeAlert = ({ open, close, save }) => { + const classes = useStyles() + + return ( + +

+ Please note that all values you set that were based on your prior fiat + currency are still the same. If you need to adjust these to reflect the + new fiat currency (such as minimum transaction amounts, fixed fees, and + compliance triggers, for example), please do so now. +

+

+ Also, if you have cash-out enabled, you must define new dispenser bill + counts for the new currency for cash-out on the new currency to work. +

+
+ + Cancel + + + Save + +
+
+ ) +} + const Locales = ({ name: SCREEN_KEY }) => { const { data } = useQuery(GET_DATA) const [saveConfig] = useMutation(SAVE_CONFIG, { refetchQueries: () => ['getData'] }) + const [dataToSave, setDataToSave] = useState(null) + const config = data?.config && fromNamespace(SCREEN_KEY)(data.config) const locale = config && !R.isEmpty(config) ? config : localeDefaults const localeOverrides = locale.overrides ?? [] - const save = it => { - const config = toNamespace(SCREEN_KEY)(it.locale[0]) - return saveConfig({ variables: { config } }) + const handleSave = it => { + const newConfig = toNamespace(SCREEN_KEY)(it.locale[0]) + + if (newConfig.locale_fiatCurrency !== config.fiatCurrency) + setDataToSave(newConfig) + else save(newConfig) + } + + const save = config => { + setDataToSave(null) + saveConfig({ variables: { config } }) } const saveOverrides = it => { @@ -72,6 +121,11 @@ const Locales = ({ name: SCREEN_KEY }) => { return ( <> + setDataToSave(null)} + save={() => dataToSave && save(dataToSave)} + />
{ name="locale" enableEdit initialValues={locale} - save={save} + save={handleSave} validationSchema={LocaleSchema} data={R.of(locale)} elements={mainFields(data)} diff --git a/new-lamassu-admin/src/pages/Locales/Locales.styles.js b/new-lamassu-admin/src/pages/Locales/Locales.styles.js new file mode 100644 index 00000000..7470d8f6 --- /dev/null +++ b/new-lamassu-admin/src/pages/Locales/Locales.styles.js @@ -0,0 +1,12 @@ +const styles = { + rightAligned: { + marginTop: '20px', + marginLeft: 'auto', + marginBottom: '20px' + }, + rightLink: { + marginLeft: '20px' + } +} + +export { styles }