Skip to content

Commit

Permalink
🔧 Update Module
Browse files Browse the repository at this point in the history
  • Loading branch information
Salah Eddine Lalami committed Oct 28, 2023
1 parent 835828e commit df43aea
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 308 deletions.
10 changes: 4 additions & 6 deletions frontend/src/components/SelectAsync/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export default function SelectAsync({
withRedirect = false,
urlToRedirect = '/',
}) {
const [isLoading, setIsLoading] = useState(false);
const [selectOptions, setOptions] = useState([]);
const [currentValue, setCurrentValue] = useState(undefined);

Expand All @@ -26,9 +25,8 @@ export default function SelectAsync({
};
const { result, isLoading: fetchIsLoading, isSuccess } = useFetch(asyncList);
useEffect(() => {
isSuccess ? setOptions(result) : setOptions([]);
setIsLoading(fetchIsLoading);
}, [fetchIsLoading]);
isSuccess && setOptions(result);
}, [isSuccess]);

const labels = (optionField) => {
return displayLabels.map((x) => optionField[x]).join(' ');
Expand All @@ -55,8 +53,8 @@ export default function SelectAsync({

return (
<Select
loading={isLoading}
disabled={isLoading}
loading={fetchIsLoading}
disabled={fetchIsLoading}
value={currentValue}
onChange={handleSelectChange}
>
Expand Down
23 changes: 2 additions & 21 deletions frontend/src/hooks/useFetch/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,7 @@ function useFetchData(fetchFunction) {
}

export default function useFetch(fetchFunction) {
const [data, setData] = useState(null);
const [isLoading, setLoading] = useState(true);
const [isSuccess, setSuccess] = useState(false);
const [error, setError] = useState(null);
const { data, isLoading, isSuccess, error } = useFetchData(fetchFunction);

useEffect(() => {
async function fetchData() {
try {
const data = await fetchFunction();
setData(data.result);
setSuccess(true);
} catch (error) {
setError(error);
} finally {
setLoading(false);
}
}

fetchData();
}, [isLoading]);

return { data, isLoading, isSuccess, error };
return { result: data, isLoading, isSuccess, error };
}
11 changes: 0 additions & 11 deletions frontend/src/modules/PaymentModule/CreatePaymentModule/index.jsx

This file was deleted.

74 changes: 0 additions & 74 deletions frontend/src/modules/PaymentModule/Forms/PaymentForm.jsx

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { ErpLayout } from '@/layout';
import PaymentERP from './components/PaymentERP';
import DataTableDropMenu from './components/DataTableDropMenu';
import ErpPanel from '@/modules/ErpPanelModule';

export default function PaymentDataTableModule({ config }) {
return (
<ErpLayout>
<PaymentERP config={config}></PaymentERP>
<ErpPanel config={config}></ErpPanel>
</ErpLayout>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import ReadItem from './components/ReadItem';
import PageLoader from '@/components/PageLoader';
import { erp } from '@/redux/erp/actions';
import { selectItemById, selectCurrentItem } from '@/redux/erp/selectors';
import { useEffect, useState } from 'react';
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useParams, useHistory } from 'react-router-dom';
import { useParams } from 'react-router-dom';

export default function ReadPaymentModule({ config }) {
const dispatch = useDispatch();
const history = useHistory();

const { id } = useParams();
let item = useSelector(selectItemById(id));

Expand All @@ -20,7 +20,6 @@ export default function ReadPaymentModule({ config }) {
} else {
dispatch(erp.read({ entity: config.entity, id }));
}
console.log('useEffect item');
}, [item]);

const { result: currentResult } = useSelector(selectCurrentItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { selectCurrentLang } from '@/redux/lang/selectors';
import Loading from '@/components/Loading';

import calculate from '@/utils/calculate';
import PaymentForm from '../../Forms/PaymentForm';
import PaymentForm from '@/forms/PaymentForm';
export default function UpdatePayment({ config, currentInvoice }) {
let { entity } = config;
const dispatch = useDispatch();
Expand Down

0 comments on commit df43aea

Please sign in to comment.