mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-26 20:54:21 +01:00
Apply 22 suggestion(s) to 6 file(s)
This commit is contained in:
parent
5be06babd7
commit
b864ba66da
@ -1,20 +1,16 @@
|
|||||||
import apiClient from './clients/api-client';
|
import apiClient from './clients/api-client';
|
||||||
import { AxiosResponse } from 'axios';
|
import { AxiosResponse } from 'axios';
|
||||||
|
import { Space } from '../models/space';
|
||||||
|
|
||||||
export default class SpaceAPI {
|
export default class SpaceAPI {
|
||||||
static async index (filters?: boolean): Promise<Array<any>> {
|
static async index (): Promise<Array<any>> {
|
||||||
const res: AxiosResponse<Array<any>> = await apiClient.get(`/api/spaces${this.filtersToQuery(filters)}`);
|
const res: AxiosResponse<Array<Space>> = await apiClient.get('/api/spaces');
|
||||||
return res?.data;
|
return res?.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async get (id: number): Promise<any> {
|
static async get (id: number): Promise<Space> {
|
||||||
const res: AxiosResponse<any> = await apiClient.get(`/api/spaces/${id}`);
|
const res: AxiosResponse<Space> = await apiClient.get(`/api/spaces/${id}`);
|
||||||
return res?.data;
|
return res?.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static filtersToQuery (filters?: boolean): string {
|
|
||||||
if (!filters) return '';
|
|
||||||
|
|
||||||
return '?' + Object.entries(filters).map(f => `${f[0]}=${f[1]}`).join('&');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ interface ConfigureExtendedPriceButtonProps {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This component is a button that shows the list of extendedPrices.
|
* This component is a button that shows the list of extendedPrices.
|
||||||
* It also triggers modal dialogs to configure (add/delete/edit/remove) extendedPrices.
|
* It also triggers modal dialogs to configure (add/edit/remove) extendedPrices.
|
||||||
*/
|
*/
|
||||||
export const ConfigureExtendedPriceButton: React.FC<ConfigureExtendedPriceButtonProps> = ({ prices, onError, onSuccess, groupId, priceableId, priceableType }) => {
|
export const ConfigureExtendedPriceButton: React.FC<ConfigureExtendedPriceButtonProps> = ({ prices, onError, onSuccess, groupId, priceableId, priceableType }) => {
|
||||||
const { t } = useTranslation('admin');
|
const { t } = useTranslation('admin');
|
||||||
@ -46,7 +46,7 @@ export const ConfigureExtendedPriceButton: React.FC<ConfigureExtendedPriceButton
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the button used to trigger the "new pack" modal
|
* Render the button used to trigger the "new extended price" modal
|
||||||
*/
|
*/
|
||||||
const renderAddButton = (): ReactNode => {
|
const renderAddButton = (): ReactNode => {
|
||||||
return <CreateExtendedPrice onSuccess={handleSuccess}
|
return <CreateExtendedPrice onSuccess={handleSuccess}
|
||||||
@ -57,7 +57,7 @@ export const ConfigureExtendedPriceButton: React.FC<ConfigureExtendedPriceButton
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="configure-packs-button">
|
<div className="configure-extended-prices-button">
|
||||||
<button className="packs-button" onClick={toggleShowList}>
|
<button className="packs-button" onClick={toggleShowList}>
|
||||||
<i className="fas fa-stopwatch" />
|
<i className="fas fa-stopwatch" />
|
||||||
</button>
|
</button>
|
||||||
|
@ -24,7 +24,7 @@ export const CreateExtendedPrice: React.FC<CreateExtendedPriceProps> = ({ onSucc
|
|||||||
const [isOpen, setIsOpen] = useState<boolean>(false);
|
const [isOpen, setIsOpen] = useState<boolean>(false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open/closes the "new pack" modal dialog
|
* Open/closes the "new extended price" modal dialog
|
||||||
*/
|
*/
|
||||||
const toggleModal = (): void => {
|
const toggleModal = (): void => {
|
||||||
setIsOpen(!isOpen);
|
setIsOpen(!isOpen);
|
||||||
@ -34,7 +34,7 @@ export const CreateExtendedPrice: React.FC<CreateExtendedPriceProps> = ({ onSucc
|
|||||||
* Callback triggered when the user has validated the creation of the new extended price
|
* Callback triggered when the user has validated the creation of the new extended price
|
||||||
*/
|
*/
|
||||||
const handleSubmit = (extendedPrice: Price): void => {
|
const handleSubmit = (extendedPrice: Price): void => {
|
||||||
// set the already-known attributes of the new pack
|
// set the already-known attributes of the new extended price
|
||||||
const newExtendedPrice = Object.assign<Price, Price>({} as Price, extendedPrice);
|
const newExtendedPrice = Object.assign<Price, Price>({} as Price, extendedPrice);
|
||||||
newExtendedPrice.group_id = groupId;
|
newExtendedPrice.group_id = groupId;
|
||||||
newExtendedPrice.priceable_id = priceableId;
|
newExtendedPrice.priceable_id = priceableId;
|
||||||
@ -58,11 +58,11 @@ export const CreateExtendedPrice: React.FC<CreateExtendedPriceProps> = ({ onSucc
|
|||||||
className="new-pack-modal"
|
className="new-pack-modal"
|
||||||
closeButton
|
closeButton
|
||||||
confirmButton={t('app.admin.create_extendedPrice.create_extendedPrice')}
|
confirmButton={t('app.admin.create_extendedPrice.create_extendedPrice')}
|
||||||
onConfirmSendFormId="new-pack">
|
onConfirmSendFormId="new-extended-price">
|
||||||
<FabAlert level="info">
|
<FabAlert level="info">
|
||||||
{t('app.admin.create_extendedPrice.new_extendedPrice_info', { TYPE: priceableType })}
|
{t('app.admin.create_extendedPrice.new_extendedPrice_info', { TYPE: priceableType })}
|
||||||
</FabAlert>
|
</FabAlert>
|
||||||
<ExtendedPriceForm formId="new-pack" onSubmit={handleSubmit} />
|
<ExtendedPriceForm formId="new-extended-price" onSubmit={handleSubmit} />
|
||||||
</FabModal>
|
</FabModal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -59,7 +59,7 @@ export const ExtendedPriceForm: React.FC<PackFormProps> = ({ formId, onSubmit, p
|
|||||||
min={1}
|
min={1}
|
||||||
icon={<i className="fas fa-clock" />}
|
icon={<i className="fas fa-clock" />}
|
||||||
required />
|
required />
|
||||||
<label htmlFor="amount">{t('app.admin.pack_form.amount')} *</label>
|
<label htmlFor="amount">{t('app.admin.extended_price_form.amount')} *</label>
|
||||||
<FabInput id="amount"
|
<FabInput id="amount"
|
||||||
type="number"
|
type="number"
|
||||||
step={0.01}
|
step={0.01}
|
||||||
|
@ -64,12 +64,16 @@ const SpacesPricing: React.FC<SpacesPricingProps> = ({ onError, onSuccess }) =>
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the price matching the given criterion
|
* Find the default price (hourly rate) matching the given criterion
|
||||||
*/
|
*/
|
||||||
const findPriceBy = (spaceId, groupId): Price => {
|
const findPriceBy = (spaceId, groupId): Price => {
|
||||||
return prices.find(price => price.priceable_id === spaceId && price.group_id === groupId);
|
return prices.find(price => price.priceable_id === spaceId && price.group_id === groupId && price.duration == 60);
|
||||||
};
|
};
|
||||||
const findPricesBy = (spaceId, groupId): Array<Price> => {
|
|
||||||
|
/**
|
||||||
|
* Find prices matching the given criterion, except the default hourly rate
|
||||||
|
*/
|
||||||
|
const findExtendedPricesBy = (spaceId, groupId): Array<Price> => {
|
||||||
return prices.filter(price => price.priceable_id === spaceId && price.group_id === groupId && price.duration !== 60);
|
return prices.filter(price => price.priceable_id === spaceId && price.group_id === groupId && price.duration !== 60);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -90,7 +94,7 @@ const SpacesPricing: React.FC<SpacesPricingProps> = ({ onError, onSuccess }) =>
|
|||||||
const handleUpdatePrice = (price: Price): void => {
|
const handleUpdatePrice = (price: Price): void => {
|
||||||
PriceAPI.update(price)
|
PriceAPI.update(price)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
onSuccess(t('app.admin.machines_pricing.price_updated'));
|
onSuccess(t('app.admin.spaces_pricing.price_updated'));
|
||||||
updatePrice(price);
|
updatePrice(price);
|
||||||
})
|
})
|
||||||
.catch(error => onError(error));
|
.catch(error => onError(error));
|
||||||
@ -116,7 +120,7 @@ const SpacesPricing: React.FC<SpacesPricingProps> = ({ onError, onSuccess }) =>
|
|||||||
{groups?.map(group => <td key={group.id}>
|
{groups?.map(group => <td key={group.id}>
|
||||||
{prices && <EditablePrice price={findPriceBy(space.id, group.id)} onSave={handleUpdatePrice} />}
|
{prices && <EditablePrice price={findPriceBy(space.id, group.id)} onSave={handleUpdatePrice} />}
|
||||||
<ConfigureExtendedPriceButton
|
<ConfigureExtendedPriceButton
|
||||||
prices={findPricesBy(space.id, group.id)}
|
prices={findExtendedPricesBy(space.id, group.id)}
|
||||||
onError={onError}
|
onError={onError}
|
||||||
onSuccess={onSuccess}
|
onSuccess={onSuccess}
|
||||||
groupId={group.id}
|
groupId={group.id}
|
||||||
|
@ -368,6 +368,8 @@ en:
|
|||||||
status_enabled: "Enabled"
|
status_enabled: "Enabled"
|
||||||
status_disabled: "Disabled"
|
status_disabled: "Disabled"
|
||||||
status_all: "All"
|
status_all: "All"
|
||||||
|
spaces_pricing:
|
||||||
|
price_updated: "Price successfully updated"
|
||||||
machines_pricing:
|
machines_pricing:
|
||||||
prices_match_machine_hours_rates_html: "The prices below match one hour of machine usage, <strong>without subscription</strong>."
|
prices_match_machine_hours_rates_html: "The prices below match one hour of machine usage, <strong>without subscription</strong>."
|
||||||
prices_calculated_on_hourly_rate_html: "All the prices will be automatically calculated based on the hourly rate defined here.<br/><em>For example</em>, if you define an hourly rate at {RATE}: a slot of {DURATION} minutes, will be charged <strong>{PRICE}</strong>."
|
prices_calculated_on_hourly_rate_html: "All the prices will be automatically calculated based on the hourly rate defined here.<br/><em>For example</em>, if you define an hourly rate at {RATE}: a slot of {DURATION} minutes, will be charged <strong>{PRICE}</strong>."
|
||||||
@ -381,6 +383,8 @@ en:
|
|||||||
configure_extendedPrices_button:
|
configure_extendedPrices_button:
|
||||||
extendedPrices: "Extended prices"
|
extendedPrices: "Extended prices"
|
||||||
no_extendedPrices: "No extended price for now"
|
no_extendedPrices: "No extended price for now"
|
||||||
|
extended_prices_form:
|
||||||
|
amount: "Price"
|
||||||
pack_form:
|
pack_form:
|
||||||
hours: "Hours"
|
hours: "Hours"
|
||||||
amount: "Price"
|
amount: "Price"
|
||||||
@ -409,7 +413,7 @@ en:
|
|||||||
pack_successfully_updated: "The prepaid pack was successfully updated."
|
pack_successfully_updated: "The prepaid pack was successfully updated."
|
||||||
create_extendedPrice:
|
create_extendedPrice:
|
||||||
new_extendedPrice: "New extended price"
|
new_extendedPrice: "New extended price"
|
||||||
new_extendedPrice_info: "..."
|
new_extendedPrice_info: "Extended prices allows you to define prices based on custom durations, intead on the default hourly rates."
|
||||||
create_extendedPrice: "Create extended price"
|
create_extendedPrice: "Create extended price"
|
||||||
extendedPrice_successfully_created: "The new extended price was successfully created."
|
extendedPrice_successfully_created: "The new extended price was successfully created."
|
||||||
delete_extendedPrice:
|
delete_extendedPrice:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user