Skip to content

Commit

Permalink
added num series field in provider manager
Browse files Browse the repository at this point in the history
  • Loading branch information
edmdz committed Aug 6, 2024
1 parent 3f33439 commit 28e2f40
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
31 changes: 26 additions & 5 deletions src/pages/Products/ProductDialog/ProviderManager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ const ProviderManagerDisplay = ({
setProviders,
selectedProvider,
price,
numSeries,
handleProviderChange,
handlePriceChange,
handleNumSeriesChange,
handleAddProvider,
handleDeleteProvider,
handleOnProviderAdded,
Expand All @@ -72,7 +74,7 @@ const ProviderManagerDisplay = ({
{editable && (
<>
<Grid container spacing={2} sx={{ mb: 2 }}>
<Grid item xs={12} sm={6}>
<Grid item xs={12} sm={4}>
<CustomSelectWithAdd
elements={providers}
label="Proveedor"
Expand All @@ -88,7 +90,7 @@ const ProviderManagerDisplay = ({
]}
/>
</Grid>
<Grid item xs={12} sm={6}>
<Grid item xs={12} sm={4}>
<TextField
label="Precio de Compra"
type="number"
Expand All @@ -97,8 +99,16 @@ const ProviderManagerDisplay = ({
fullWidth
/>
</Grid>
<Grid item xs={12} sm={4}>
<TextField
label="Número de Series"
value={numSeries}
onChange={handleNumSeriesChange}
fullWidth
/>
</Grid>
</Grid>
<Button onClick={handleAddProvider} variant="contained" sx={{ mt: 2 }} disabled={!selectedProvider || !price}>
<Button onClick={handleAddProvider} variant="contained" sx={{ mt: 2 }} disabled={!selectedProvider || !price || !numSeries}>
Agregar Proveedor
</Button>
</>
Expand All @@ -108,6 +118,7 @@ const ProviderManagerDisplay = ({
<TableRow>
<TableCell>Proveedor</TableCell>
<TableCell align="right">Precio de Compra</TableCell>
<TableCell align="right">Número de Series</TableCell>
{editable && <TableCell align="right">Acciones</TableCell>}
</TableRow>
</TableHead>
Expand All @@ -120,6 +131,7 @@ const ProviderManagerDisplay = ({
>
<TableCell>{providerProduct.provider.name}</TableCell>
<TableCell align="right">{providerProduct.price.cost}</TableCell>
<TableCell align="right">{providerProduct.numSeries}</TableCell>
{editable && (
<TableCell align="right">
<IconButton
Expand All @@ -144,6 +156,7 @@ const ProviderManager = ({ editable = true }) => {
const [providers, setProviders] = useState([]);
const [selectedProvider, setSelectedProvider] = useState(null);
const [price, setPrice] = useState('');
const [numSeries, setNumSeries] = useState('');
const [modalOpen, setModalOpen] = useState(false);
const [selectedModalProvider, setSelectedModalProvider] = useState(null);
const { openSnackbar } = useSnackbar();
Expand Down Expand Up @@ -171,19 +184,25 @@ const ProviderManager = ({ editable = true }) => {
setPrice(event.target.value);
};

const handleNumSeriesChange = (event) => {
setNumSeries(event.target.value);
};

const handleAddProvider = () => {
if (selectedProvider && price) {
if (selectedProvider && price && numSeries) {
const newProviderProduct = {
providerId: selectedProvider.id,
provider: selectedProvider,
price: {
cost: parseFloat(price),
description: `Precio de compra de ${selectedProvider.name}`
}
},
numSeries: numSeries
};
handleSetProduct(modifyAndClone(product, 'providers', [...(product.providers || []), newProviderProduct]));
setSelectedProvider(null);
setPrice('');
setNumSeries('');
}
};

Expand Down Expand Up @@ -214,9 +233,11 @@ const ProviderManager = ({ editable = true }) => {
providers={providers}
selectedProvider={selectedProvider}
price={price}
numSeries={numSeries}
setProviders={setProviders}
handleProviderChange={handleProviderChange}
handlePriceChange={handlePriceChange}
handleNumSeriesChange={handleNumSeriesChange}
handleAddProvider={handleAddProvider}
handleDeleteProvider={handleDeleteProvider}
handleOnProviderAdded={handleOnProviderAdded}
Expand Down
2 changes: 1 addition & 1 deletion src/services/BrandService.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const getAllBrands = async (name = '') => {
return Array.isArray(result.response) ? result.response.map(brand => new Brand(brand)) : [];
};

const getCarModelsByBrandId = async (brandId, name) => {
const getCarModelsByBrandId = async (brandId, name='') => {
const result = await axios.get(`/brand/${brandId}/models?name=${name}`);
return Array.isArray(result.response) ? result.response.map(model => new CarModel(model)) : [];
};
Expand Down

0 comments on commit 28e2f40

Please sign in to comment.