diff --git a/client/src/containers/Dashboard/Preferences/General.js b/client/src/containers/Dashboard/Preferences/General.js index a7c3d9c75..b7031dc4e 100644 --- a/client/src/containers/Dashboard/Preferences/General.js +++ b/client/src/containers/Dashboard/Preferences/General.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState, useCallback, useMemo } from 'react'; import { useFormik } from 'formik'; import * as Yup from 'yup'; import { @@ -6,63 +6,350 @@ import { FormGroup, InputGroup, Intent, -} from "@blueprintjs/core"; -import {optionsMapToArray} from 'utils'; + MenuItem, + Classes, +} from '@blueprintjs/core'; -function GeneralPreferences({ +import { optionsMapToArray, momentFormatter } from 'utils'; +import { TimezonePicker } from '@blueprintjs/timezone'; +import { Select } from '@blueprintjs/select'; +import classNames from 'classnames'; +import ErrorMessage from 'components/ErrorMessage'; +import Icon from 'components/Icon'; -}) { +function GeneralPreferences(props) { + const [selectedItems, setSelectedItems] = useState({}); + const [disableItems, setDisableItems] = useState(false); + const [timeZone, setTimeZone] = useState(''); + + const businessLocation = [ + { id: 218, name: 'LIBYA', code: 'LY' }, + { id: 380, name: 'UKRAINE', code: 'UA' }, + { id: 212, name: 'Morocco', code: 'MA' }, + ]; + const languagesDisplay = [ + { name: 'EN', label: 'English' }, + { name: 'Arb', label: 'Arabic' }, + ]; + const currencies = [ + { id: 0, name: 'US Dollar', code: 'USD' }, + { id: 1, name: 'Euro', code: 'EUR' }, + { id: 2, name: 'Libyan Dinar ', code: 'LYD' }, + ]; + const fiscalYear = [ + { id: 0, name: 'January-July', label: 'January-July' }, + { id: 1, name: 'August-December', label: 'August-December' }, + ]; + const dateFormat = [ + { name: '04/11/2020', format: 'MM-DD-YY' }, + { name: '2020/03/21', format: 'YY/MM/DD' }, + { name: 'Apr 11, 2020', format: 'MMMM yyyy' }, + { name: 'Saturday, Apr 11, 2020', format: 'EEEE, MMM d, yyyy' }, + ]; const validationSchema = Yup.object().shape({ - organization_name: Yup.string().required(), - organization_industry: Yup.string().required(), + organization_name: Yup.string().required('required field'), + organization_industry: Yup.string().required('required field'), + business_location: Yup.string().required('required field'), + base_currency: Yup.string().required('required field'), + fiscal_year: Yup.string().required('required field'), + language: Yup.string().required('required field'), + time_zone: Yup.date().required('required field'), + date_format: Yup.date().required('required field'), }); const formik = useFormik({ enableReinitialize: true, - initialValues: { - }, + initialValues: {}, validationSchema: validationSchema, onSubmit: (values) => { - const options = optionsMapToArray(values).map(option => { - return {...option, group: 'general'}; + const options = optionsMapToArray(values).map((option) => { + return { ...option, group: 'general' }; }); - }, }); + const { errors, values, touched } = useMemo(() => formik, [formik]); + + const businessLocationItem = (item, { handleClick }) => ( + + ); + + const currencyItem = (item, { handleClick }) => ( + + ); + const fiscalYearItem = (item, { handleClick }) => ( + + ); + + const languageItem = (item, { handleClick }) => ( + + ); + + const data_Format = (item, { handleClick }) => ( + + ); + + const onItemsSelect = (filedName) => { + return (filed) => { + setSelectedItems({ + ...selectedItems, + [filedName]: filed, + }); + formik.setFieldValue(filedName, filed.name); + }; + }; + const getSelectedItemLabel = (filedName, defaultLabel) => { + return typeof selectedItems[filedName] !== 'undefined' + ? selectedItems[filedName].name + : defaultLabel; + }; + + const handleTimezoneChange = (timezone) => setTimeZone(timezone); return ( -