mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
fix(vendor & customer): floting action.
This commit is contained in:
@@ -84,7 +84,7 @@ function CustomerForm({
|
||||
() => ({
|
||||
...defaultInitialValues,
|
||||
currency_code: baseCurrency,
|
||||
...transformToForm(customer || contactDuplicate, defaultInitialValues),
|
||||
...transformToForm(contactDuplicate || customer, defaultInitialValues),
|
||||
}),
|
||||
[customer, contactDuplicate, baseCurrency],
|
||||
);
|
||||
|
||||
@@ -57,7 +57,6 @@ function CustomerFormProvider({ customerId, ...props }) {
|
||||
return (
|
||||
<DashboardInsider
|
||||
loading={
|
||||
isCustomerLoading ||
|
||||
isCustomerLoading ||
|
||||
isCurrenciesLoading ||
|
||||
isContactLoading
|
||||
|
||||
@@ -25,7 +25,7 @@ export default function VendorFloatingActions() {
|
||||
const { resetForm, isSubmitting, submitForm } = useFormikContext();
|
||||
|
||||
// Vendor form context.
|
||||
const { vendor, setSubmitPayload } = useVendorFormContext();
|
||||
const { isNewMode, setSubmitPayload } = useVendorFormContext();
|
||||
|
||||
// History.
|
||||
const history = useHistory();
|
||||
@@ -62,7 +62,7 @@ export default function VendorFloatingActions() {
|
||||
intent={Intent.PRIMARY}
|
||||
type="submit"
|
||||
onClick={handleSubmitBtnClick}
|
||||
text={vendor ? <T id={'edit'} /> : <T id={'save'} />}
|
||||
text={!isNewMode ? <T id={'edit'} /> : <T id={'save'} />}
|
||||
/>
|
||||
<Popover
|
||||
content={
|
||||
@@ -89,7 +89,7 @@ export default function VendorFloatingActions() {
|
||||
className={'ml1'}
|
||||
disabled={isSubmitting}
|
||||
onClick={handleClearBtnClick}
|
||||
text={vendor ? <T id={'reset'} /> : <T id={'clear'} />}
|
||||
text={!isNewMode ? <T id={'reset'} /> : <T id={'clear'} />}
|
||||
/>
|
||||
{/* ----------- Cancel ----------- */}
|
||||
<Button
|
||||
|
||||
@@ -78,9 +78,10 @@ function VendorForm({
|
||||
editVendorMutate,
|
||||
setSubmitPayload,
|
||||
submitPayload,
|
||||
isNewMode,
|
||||
} = useVendorFormContext();
|
||||
|
||||
const isNewMode = !vendorId;
|
||||
// const isNewMode = !vendorId;
|
||||
|
||||
// History context.
|
||||
const history = useHistory();
|
||||
@@ -94,17 +95,11 @@ function VendorForm({
|
||||
() => ({
|
||||
...defaultInitialValues,
|
||||
currency_code: baseCurrency,
|
||||
...transformToForm(vendor || contactDuplicate, defaultInitialValues),
|
||||
...transformToForm(contactDuplicate || vendor, defaultInitialValues),
|
||||
}),
|
||||
[vendor, contactDuplicate, baseCurrency],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
!isNewMode
|
||||
? changePageTitle(formatMessage({ id: 'edit_vendor' }))
|
||||
: changePageTitle(formatMessage({ id: 'new_vendor' }));
|
||||
}, [changePageTitle, isNewMode, formatMessage]);
|
||||
|
||||
// Handles the form submit.
|
||||
const handleFormSubmit = (
|
||||
values,
|
||||
@@ -136,10 +131,10 @@ function VendorForm({
|
||||
setSubmitting(false);
|
||||
};
|
||||
|
||||
if (vendor && vendor.id) {
|
||||
editVendorMutate([vendor.id, requestForm]).then(onSuccess).catch(onError);
|
||||
} else {
|
||||
if (isNewMode) {
|
||||
createVendorMutate(requestForm).then(onSuccess).catch(onError);
|
||||
} else {
|
||||
editVendorMutate([vendor.id, requestForm]).then(onSuccess).catch(onError);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ const VendorFormContext = createContext();
|
||||
function VendorFormProvider({ vendorId, ...props }) {
|
||||
const { state } = useLocation();
|
||||
|
||||
const contactId = state?.action;
|
||||
|
||||
// Handle fetch Currencies data table
|
||||
const { data: currencies, isLoading: isCurrenciesLoading } = useCurrencies();
|
||||
|
||||
@@ -27,13 +29,11 @@ function VendorFormProvider({ vendorId, ...props }) {
|
||||
enabled: !!vendorId,
|
||||
});
|
||||
|
||||
const contactId = state?.action;
|
||||
|
||||
// Handle fetch contact duplicate details.
|
||||
const { data: contactDuplicate, isLoading: isContactLoading } = useContact(
|
||||
contactId,
|
||||
{ enabled: !!contactId },
|
||||
);
|
||||
const {
|
||||
data: contactDuplicate,
|
||||
isLoading: isContactLoading,
|
||||
} = useContact(contactId, { enabled: !!contactId });
|
||||
|
||||
// Create and edit vendor mutations.
|
||||
const { mutateAsync: createVendorMutate } = useCreateVendor();
|
||||
@@ -42,12 +42,16 @@ function VendorFormProvider({ vendorId, ...props }) {
|
||||
// Form submit payload.
|
||||
const [submitPayload, setSubmitPayload] = useState({});
|
||||
|
||||
// determines whether the form new or duplicate mode.
|
||||
const isNewMode = contactId || !vendorId;
|
||||
|
||||
const provider = {
|
||||
vendorId,
|
||||
currencies,
|
||||
vendor,
|
||||
contactDuplicate: { ...omit(contactDuplicate, ['opening_balance_at']) },
|
||||
submitPayload,
|
||||
isNewMode,
|
||||
|
||||
createVendorMutate,
|
||||
editVendorMutate,
|
||||
|
||||
Reference in New Issue
Block a user