diff --git a/components/FormError.tsx b/components/FormError.tsx new file mode 100644 index 0000000..c255847 --- /dev/null +++ b/components/FormError.tsx @@ -0,0 +1,25 @@ +import React from "react"; +import { FormikErrors, FormikTouched } from "formik"; + +export interface FormErrorProps { + errors: FormikErrors; + touched: FormikTouched; + name: string; + className?: string; +} + +const FormError: React.FC = (props) => { + if (props.errors[props.name]) { + return ( + + {props.errors[props.name]} + + ); + } + + return null; +}; + +export default FormError; diff --git a/components/Input.tsx b/components/Input.tsx index e44fd1c..05ca424 100644 --- a/components/Input.tsx +++ b/components/Input.tsx @@ -36,13 +36,15 @@ const Input: React.FC> = (props) => { return ( {props.label && ( - ); diff --git a/forms/AccountDetails.tsx b/forms/AccountDetails.tsx index d94fce9..8459f2b 100644 --- a/forms/AccountDetails.tsx +++ b/forms/AccountDetails.tsx @@ -17,12 +17,13 @@ import { Formik, Form, Field } from "formik"; import { useIntl } from "react-intl"; import * as Yup from "yup"; +import FormError from "components/FormError"; import Button from "components/Button"; import Input from "components/Input"; const validationSchema = Yup.object().shape({ - givenName: Yup.string().required("Required"), - familyName: Yup.string().required("Required"), + givenName: Yup.string().required("Required").nullable(), + familyName: Yup.string().required("Required").nullable(), }); export interface AccountDetailsFormProps { @@ -44,30 +45,22 @@ const AccountDetails: React.FC = (props) => { onSubmit={props.onSubmit} validationSchema={validationSchema} > -
- - -
- -
- + {({ errors, touched }) => ( +
+ + + + +
+ +
+ + )} ); }; diff --git a/forms/CategoryForm.tsx b/forms/CategoryForm.tsx index f8b5cb2..9efd85f 100644 --- a/forms/CategoryForm.tsx +++ b/forms/CategoryForm.tsx @@ -17,13 +17,14 @@ import { Formik, Form, Field } from "formik"; import { useIntl } from "react-intl"; import * as Yup from "yup"; +import FormError from "components/FormError"; import Input from "components/Input"; import EmojiPicker from "components/EmojiPicker"; import Button from "components/Button"; const validationSchema = Yup.object().shape({ - name: Yup.string().required("Required"), - icon: Yup.string().required("Required"), + name: Yup.string().required("Required").nullable(), + icon: Yup.string().required("Required").nullable(), }); export interface CategoryFormProps { @@ -45,22 +46,22 @@ const CategoryForm: React.FC = (props) => { onSubmit={props.onSubmit} validationSchema={validationSchema} > -
- - - - + {({ errors, touched }) => ( +
+ + +
+ + +
+ + + )} ); }; diff --git a/forms/TransactionForm.tsx b/forms/TransactionForm.tsx index 0873851..a676b6a 100644 --- a/forms/TransactionForm.tsx +++ b/forms/TransactionForm.tsx @@ -21,14 +21,15 @@ import Link from "next/link"; import { useQuery } from "@apollo/client"; import * as Yup from "yup"; import { GET_CATEGORIES } from "constants/queries"; +import FormError from "components/FormError"; import Input from "components/Input"; import Button from "components/Button"; import Loading from "components/Loading"; const validationSchema = Yup.object().shape({ - amount: Yup.number().required("Required"), - date: Yup.date().required("Required"), - category: Yup.string().required("Required"), + amount: Yup.number().required("Required").nullable(), + date: Yup.date().required("Required").nullable(), + category: Yup.string().required("Required").nullable(), }); export interface TransactionFormProps { @@ -68,15 +69,14 @@ const TransactionForm: React.FC = (props) => { type="number" placeholder="1,000" label="Amount" - className="mb-4" /> - + + {!data.queryCategory.length ? (
@@ -86,7 +86,7 @@ const TransactionForm: React.FC = (props) => {
) : ( -
+

Select category

{data.queryCategory.map((category: any) => ( ))} +
)}
diff --git a/next-env.d.ts b/next-env.d.ts index 3c20b0e..9bc3dd4 100644 --- a/next-env.d.ts +++ b/next-env.d.ts @@ -1,19 +1,3 @@ -/** - * Copyright 2022 Synchronous Technologies Pte Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - /// /// /// diff --git a/package.json b/package.json index 5d55b81..a0668ce 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "i18n:extract": "formatjs extract 'pages/**/*.ts*' 'components/**/*.ts*' --out-file lang/en.json", "i18n:compile": "formatjs compile-folder lang compiled-lang", "cdk": "cdk", - "addlicense": "addlicense -c 'Synchronous Technologies Pte Ltd' -l apache -ignore 'node_modules/**' -ignore '.next/**' -ignore 'compiled-lang/**' -ignore 'lang/**' ." + "addlicense": "addlicense -c 'Synchronous Technologies Pte Ltd' -l apache -ignore 'node_modules/**' -ignore '.next/**' -ignore 'compiled-lang/**' -ignore 'lang/**' -ingore 'next-env.d.ts' ." }, "dependencies": { "@apollo/client": "^3.5.10",