From 69c4519647a32b18d65245b66c08e1d79d3303e6 Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Thu, 11 Aug 2022 11:20:52 +0200 Subject: [PATCH] feat: add project select to sales & purchases --- .../Projects/components/ProjectsSelect.tsx | 17 +++++++++--- .../ProjectTimeEntryFormFields.tsx | 1 - .../Bills/BillForm/BillFormHeaderFields.tsx | 25 ++++++++++++++--- .../Bills/BillForm/BillFormProvider.tsx | 8 ++++++ .../Purchases/Bills/BillForm/components.tsx | 10 +++++++ .../EstimateForm/EstimateFormHeaderFields.tsx | 27 ++++++++++++++++--- .../EstimateForm/EstimateFormProvider.tsx | 9 ++++++- .../Estimates/EstimateForm/components.tsx | 10 +++++++ .../InvoiceForm/InvoiceFormHeaderFields.tsx | 24 +++++++++++++++-- .../InvoiceForm/InvoiceFormProvider.tsx | 8 ++++++ .../Sales/Invoices/InvoiceForm/components.tsx | 10 +++++++ .../PaymentReceiveFormProvider.tsx | 11 ++++++-- .../PaymentReceiveHeaderFields.tsx | 26 ++++++++++++++++-- .../PaymentReceiveForm/components.tsx | 9 +++++++ .../ReceiptForm/ReceiptFormHeaderFields.tsx | 25 +++++++++++++++-- .../ReceiptForm/ReceiptFormProvider.tsx | 8 ++++++ .../Sales/Receipts/ReceiptForm/components.tsx | 15 ++++++++--- src/lang/en/index.json | 8 +++++- 18 files changed, 228 insertions(+), 23 deletions(-) diff --git a/src/containers/Projects/components/ProjectsSelect.tsx b/src/containers/Projects/components/ProjectsSelect.tsx index ec8e04859..835b1d702 100644 --- a/src/containers/Projects/components/ProjectsSelect.tsx +++ b/src/containers/Projects/components/ProjectsSelect.tsx @@ -2,6 +2,8 @@ import React from 'react'; import intl from 'react-intl-universal'; import { MenuItem, Button } from '@blueprintjs/core'; import { FSelect } from '@/components'; +import { CLASSES } from '@/constants/classes'; +import classNames from 'classnames'; /** * @@ -31,7 +33,6 @@ const projectsItemPredicate = (query, project, _index, exactMatch) => { const projectsItemRenderer = (project, { handleClick, modifiers, query }) => { return ( ; +export function ProjectsSelect({ projects, popoverFill, ...rest }) { + return ( + + ); } /** * diff --git a/src/containers/Projects/containers/ProjectTimeEntryFormDialog/ProjectTimeEntryFormFields.tsx b/src/containers/Projects/containers/ProjectTimeEntryFormDialog/ProjectTimeEntryFormFields.tsx index 5f961fb74..35ec95266 100644 --- a/src/containers/Projects/containers/ProjectTimeEntryFormDialog/ProjectTimeEntryFormFields.tsx +++ b/src/containers/Projects/containers/ProjectTimeEntryFormDialog/ProjectTimeEntryFormFields.tsx @@ -48,7 +48,6 @@ function ProjectTimeEntryFormFields() { name={'project_id'} projects={projects} input={ProjectSelectButton} - popoverProps={{ minimal: true }} /> diff --git a/src/containers/Purchases/Bills/BillForm/BillFormHeaderFields.tsx b/src/containers/Purchases/Bills/BillForm/BillFormHeaderFields.tsx index c9b5e0172..0c36d7fb9 100644 --- a/src/containers/Purchases/Bills/BillForm/BillFormHeaderFields.tsx +++ b/src/containers/Purchases/Bills/BillForm/BillFormHeaderFields.tsx @@ -1,7 +1,7 @@ import React from 'react'; import styled from 'styled-components'; import classNames from 'classnames'; -import { FormGroup, InputGroup, Position } from '@blueprintjs/core'; +import { FormGroup, InputGroup, Classes, Position } from '@blueprintjs/core'; import { FastField, ErrorMessage } from 'formik'; import { DateInput } from '@blueprintjs/datetime'; import { FormattedMessage as T } from '@/components'; @@ -17,7 +17,11 @@ import { import { useBillFormContext } from './BillFormProvider'; import { vendorsFieldShouldUpdate } from './utils'; -import { BillExchangeRateInputField } from './components'; +import { + BillExchangeRateInputField, + BillProjectSelectButton, +} from './components'; +import { ProjectsSelect } from '@/containers/Projects/components'; import withDialogActions from '@/containers/Dialog/withDialogActions'; import { momentFormatter, @@ -32,7 +36,7 @@ import { */ function BillFormHeader() { // Bill form context. - const { vendors } = useBillFormContext(); + const { vendors, projects } = useBillFormContext(); return (
@@ -163,6 +167,21 @@ function BillFormHeader() { )} + + {/*------------ Project name -----------*/} + } + inline={true} + className={classNames('form-group--select-list', Classes.FILL)} + > + +
); } diff --git a/src/containers/Purchases/Bills/BillForm/BillFormProvider.tsx b/src/containers/Purchases/Bills/BillForm/BillFormProvider.tsx index 6d2485b9e..ae38ef493 100644 --- a/src/containers/Purchases/Bills/BillForm/BillFormProvider.tsx +++ b/src/containers/Purchases/Bills/BillForm/BillFormProvider.tsx @@ -2,6 +2,7 @@ import React, { createContext, useState } from 'react'; import { Features } from '@/constants'; import { useFeatureCan } from '@/hooks/state'; import { DashboardInsider } from '@/components/Dashboard'; +import { useProjects } from '@/containers/Projects/hooks'; import { useAccounts, useVendors, @@ -80,6 +81,12 @@ function BillFormProvider({ billId, ...props }) { isSuccess: isBranchesSuccess, } = useBranches({}, { enabled: isBranchFeatureCan }); + // Fetches the projects list. + const { + data: { projects }, + isLoading: isProjectsLoading, + } = useProjects(); + // Handle fetching bill settings. const { isFetching: isSettingLoading } = useSettings(); @@ -102,6 +109,7 @@ function BillFormProvider({ billId, ...props }) { bill, warehouses, branches, + projects, submitPayload, isNewMode, diff --git a/src/containers/Purchases/Bills/BillForm/components.tsx b/src/containers/Purchases/Bills/BillForm/components.tsx index 53d620c87..207cc124e 100644 --- a/src/containers/Purchases/Bills/BillForm/components.tsx +++ b/src/containers/Purchases/Bills/BillForm/components.tsx @@ -1,4 +1,6 @@ import React from 'react'; +import intl from 'react-intl-universal'; +import { Button } from '@blueprintjs/core'; import { useFormikContext } from 'formik'; import { ExchangeRateInputGroup } from '@/components'; import { useCurrentOrganization } from '@/hooks/state'; @@ -26,3 +28,11 @@ export function BillExchangeRateInputField({ ...props }) { /> ); } + +/** + * bill project select. + * @returns {JSX.Element} + */ + export function BillProjectSelectButton({ label }) { + return