1
0
This commit is contained in:
Ahmed Bouhuolia
2026-03-27 01:08:57 +02:00
parent 2e90e3cc5b
commit 5ba753e808
7 changed files with 29 additions and 42 deletions
@@ -3,7 +3,7 @@ import React from 'react';
import { useParams, useHistory } from 'react-router-dom'; import { useParams, useHistory } from 'react-router-dom';
import styled from 'styled-components'; import styled from 'styled-components';
import { Box, DashboardCard, DashboardInsider } from '@/components'; import { Box, DashboardCard, DashboardInsider } from '@/components';
import { CustomerFormFormik } from './CustomerFormFormik'; import { CustomerFormFormik, ustomerFormFormik } from './CustomerFormFormik';
import { import {
CustomerFormProvider, CustomerFormProvider,
useCustomerFormContext, useCustomerFormContext,
@@ -14,25 +14,34 @@ import {
* @returns {JSX} * @returns {JSX}
*/ */
export default function CustomerFormPage() { export default function CustomerFormPage() {
const history = useHistory();
const { id } = useParams(); const { id } = useParams();
const { isFormLoading } = useCustomerFormContext();
const customerId = parseInt(id, 10); const customerId = parseInt(id, 10);
// Handle the form submit success. return (
<CustomerFormProvider customerId={customerId}>
<CustomerFormPageContent />
</CustomerFormProvider>
);
}
function CustomerFormPageContent() {
const history = useHistory();
const { isFormLoading } = useCustomerFormContext();
const handleSubmitSuccess = (values, formArgs, submitPayload) => { const handleSubmitSuccess = (values, formArgs, submitPayload) => {
if (!submitPayload.noRedirect) { if (!submitPayload.noRedirect) {
history.push('/customers'); history.push('/customers');
} }
}; }
// Handle the form cancel button click. // Handle the form cancel button click.
const handleFormCancel = () => { const handleFormCancel = () => {
history.goBack(); history.goBack();
}; };
return ( return (
<CustomerFormProvider customerId={customerId}>
<DashboardInsider loading={isFormLoading}> <DashboardInsider loading={isFormLoading}>
<Box mx={'auto'} maxWidth={800}> <Box mx={'auto'} maxWidth={800}>
<CustomerFormFormik <CustomerFormFormik
@@ -41,6 +50,5 @@ export default function CustomerFormPage() {
/> />
</Box> </Box>
</DashboardInsider> </DashboardInsider>
</CustomerFormProvider> )
);
} }
@@ -63,7 +63,7 @@ const CustomerFormContext = createContext<CustomerFormContextValue | undefined>(
undefined, undefined,
); );
function CustomerFormProvider({ query, customerId, children }: CustomerFormProviderProps) { export function CustomerFormProvider({ query, customerId, children }: CustomerFormProviderProps) {
const { state } = useLocation<{ action?: number | string }>(); const { state } = useLocation<{ action?: number | string }>();
const contactId = state?.action; const contactId = state?.action;
@@ -132,7 +132,7 @@ function CustomerFormProvider({ query, customerId, children }: CustomerFormProvi
); );
} }
const useCustomerFormContext = () => { export const useCustomerFormContext = () => {
const ctx = React.useContext(CustomerFormContext); const ctx = React.useContext(CustomerFormContext);
if (!ctx) { if (!ctx) {
throw new Error( throw new Error(
@@ -141,5 +141,3 @@ const useCustomerFormContext = () => {
} }
return ctx; return ctx;
}; };
export { CustomerFormProvider, useCustomerFormContext };
@@ -8,8 +8,8 @@ import {
VendorFormProvider, VendorFormProvider,
useVendorFormContext, useVendorFormContext,
} from '@/containers/Vendors/VendorForm/VendorFormProvider'; } from '@/containers/Vendors/VendorForm/VendorFormProvider';
import VendorFormFormik, { import {
VendorFormHeaderPrimary, VendorFormFormik,
} from '@/containers/Vendors/VendorForm/VendorFormFormik'; } from '@/containers/Vendors/VendorForm/VendorFormFormik';
import { withDrawerActions } from '@/containers/Drawer/withDrawerActions'; import { withDrawerActions } from '@/containers/Drawer/withDrawerActions';
@@ -62,13 +62,11 @@ function QuickVendorFormDrawer({
return ( return (
<VendorFormProvider vendorId={vendorId}> <VendorFormProvider vendorId={vendorId}>
<DrawerVendorFormLoading> <DrawerVendorFormLoading>
<VendorFormCard>
<VendorFormFormik <VendorFormFormik
initialValues={{ first_name: displayName }} initialValues={{ first_name: displayName }}
onSubmitSuccess={handleSubmitSuccess} onSubmitSuccess={handleSubmitSuccess}
onCancel={handleCancelForm} onCancel={handleCancelForm}
/> />
</VendorFormCard>
</DrawerVendorFormLoading> </DrawerVendorFormLoading>
</VendorFormProvider> </VendorFormProvider>
); );
@@ -79,20 +77,3 @@ export default R.compose(
withDashboardActions, withDashboardActions,
)(QuickVendorFormDrawer); )(QuickVendorFormDrawer);
const VendorFormCard = styled(Card)`
margin: 15px;
padding: 25px;
margin-bottom: calc(15px + 65px);
${VendorFormHeaderPrimary} {
padding-top: 0;
}
.page-form {
padding: 0;
&__floating-actions {
margin-left: -41px;
margin-right: -41px;
}
}
`;
@@ -18,7 +18,6 @@ export default function QuickWriteVendorDrawerContent({ displayName, autofillRef
<DrawerHeaderContent <DrawerHeaderContent
name={DRAWERS.QUICK_CREATE_CUSTOMER} name={DRAWERS.QUICK_CREATE_CUSTOMER}
title={<T id={'create_a_new_vendor'} />} title={<T id={'create_a_new_vendor'} />}
/> />
<DrawerBody> <DrawerBody>
<QuickVendorFormDrawer displayName={displayName} autofillRef={autofillRef} /> <QuickVendorFormDrawer displayName={displayName} autofillRef={autofillRef} />
@@ -101,7 +101,7 @@ function VendorFormFormikBase({
}; };
return ( return (
<Box mx={'auto'} maxWidth={800}>
<Formik <Formik
validationSchema={ validationSchema={
isNewMode ? CreateVendorFormSchema : EditVendorFormSchema isNewMode ? CreateVendorFormSchema : EditVendorFormSchema
@@ -115,7 +115,6 @@ function VendorFormFormikBase({
</VendorFormFields> </VendorFormFields>
</Form> </Form>
</Formik> </Formik>
</Box>
); );
} }
@@ -2,7 +2,7 @@
import React from 'react'; import React from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import { useParams, useHistory } from 'react-router-dom'; import { useParams, useHistory } from 'react-router-dom';
import { DashboardCard, DashboardInsider } from '@/components'; import { Box, DashboardCard, DashboardInsider } from '@/components';
import { VendorFormProvider, useVendorFormContext } from './VendorFormProvider'; import { VendorFormProvider, useVendorFormContext } from './VendorFormProvider';
import { VendorFormFormik } from './VendorFormFormik'; import { VendorFormFormik } from './VendorFormFormik';
@@ -41,10 +41,12 @@ export function VendorFormPage() {
return ( return (
<VendorFormProvider vendorId={id}> <VendorFormProvider vendorId={id}>
<VendorFormPageLoading> <VendorFormPageLoading>
<Box mx={'auto'} maxWidth={800}>
<VendorFormFormik <VendorFormFormik
onSubmitSuccess={handleSubmitSuccess} onSubmitSuccess={handleSubmitSuccess}
onCancel={handleFormCancel} onCancel={handleFormCancel}
/> />
</Box>
</VendorFormPageLoading> </VendorFormPageLoading>
</VendorFormProvider> </VendorFormProvider>
); );
+1 -1
View File
@@ -631,7 +631,7 @@ export const getDashboardRoutes = () => [
{ {
path: `/vendors/new`, path: `/vendors/new`,
component: lazy( component: lazy(
() => import('@/containers/Vendors/VendorForm/VendorFormPage'), () => import('@/containers/Vendors/VendorForm/VendorFormPage').then(module => ({ default: module.VendorFormPage })),
), ),
name: 'vendor-new', name: 'vendor-new',
breadcrumb: intl.get('new_vendor'), breadcrumb: intl.get('new_vendor'),