1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

Merge branch 'spaces_multiprices_front' into spaces_multiprices

This commit is contained in:
vincent 2021-12-21 18:06:25 +01:00
commit 0d34bffa6d
2 changed files with 13 additions and 6 deletions

View File

@ -41,7 +41,7 @@ export const ConfigureExtendedPriceButton: React.FC<ConfigureExtendedPriceButton
const handleSuccess = (message: string) => {
onSuccess(message);
PriceAPI.index({ group_id: groupId, priceable_id: priceableId, priceable_type: priceableType })
.then(data => setExtendedPrices(data))
.then(data => setExtendedPrices(data.filter(p => p.duration !== 60)))
.catch(error => onError(error));
};
@ -59,7 +59,7 @@ export const ConfigureExtendedPriceButton: React.FC<ConfigureExtendedPriceButton
return (
<div className="configure-packs-button">
<button className="packs-button" onClick={toggleShowList}>
<i className="fas fa-box" />
<i className="fas fa-stopwatch" />
</button>
{showList && <FabPopover title={t('app.admin.configure_extendedPrices_button.extendedPrices')} headerButton={renderAddButton()} className="fab-popover__right">
<ul>

View File

@ -8,6 +8,7 @@ import SpaceAPI from '../../api/space';
import GroupAPI from '../../api/group';
import { Group } from '../../models/group';
import { IApplication } from '../../models/application';
import { Space } from '../../models/space';
import { EditablePrice } from './editable-price';
import { ConfigureExtendedPriceButton } from './configure-extended-price-button';
import PriceAPI from '../../api/price';
@ -28,9 +29,9 @@ interface SpacesPricingProps {
const SpacesPricing: React.FC<SpacesPricingProps> = ({ onError, onSuccess }) => {
const { t } = useTranslation('admin');
const [spaces, setSpaces] = useState<Array<any>>(null);
const [spaces, setSpaces] = useState<Array<Space>>(null);
const [groups, setGroups] = useState<Array<Group>>(null);
const [prices, updatePrices] = useImmer<Array<Price>>(null);
const [prices, updatePrices] = useImmer<Array<Price>>([]);
// retrieve the initial data
useEffect(() => {
@ -62,8 +63,14 @@ const SpacesPricing: React.FC<SpacesPricingProps> = ({ onError, onSuccess }) =>
return FormatLib.price(price);
};
/**
* Find the price matching the given criterion
*/
const findPriceBy = (spaceId, groupId): Price => {
return prices.find(price => price.priceable_id === spaceId && price.group_id === groupId);
};
const findPricesBy = (spaceId, groupId): Array<Price> => {
return prices.filter(price => price.priceable_id === spaceId && price.group_id === groupId);
return prices.filter(price => price.priceable_id === spaceId && price.group_id === groupId && price.duration !== 60);
};
/**
@ -107,7 +114,7 @@ const SpacesPricing: React.FC<SpacesPricingProps> = ({ onError, onSuccess }) =>
{spaces?.map(space => <tr key={space.id}>
<td>{space.name}</td>
{groups?.map(group => <td key={group.id}>
{prices && <EditablePrice price={findPricesBy(space.id, group.id)[0]} onSave={handleUpdatePrice} />}
{prices && <EditablePrice price={findPriceBy(space.id, group.id)} onSave={handleUpdatePrice} />}
<ConfigureExtendedPriceButton
prices={findPricesBy(space.id, group.id)}
onError={onError}