mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-01 12:24:28 +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 { AxiosResponse } from 'axios';
|
||||
import { Space } from '../models/space';
|
||||
|
||||
export default class SpaceAPI {
|
||||
static async index (filters?: boolean): Promise<Array<any>> {
|
||||
const res: AxiosResponse<Array<any>> = await apiClient.get(`/api/spaces${this.filtersToQuery(filters)}`);
|
||||
static async index (): Promise<Array<any>> {
|
||||
const res: AxiosResponse<Array<Space>> = await apiClient.get('/api/spaces');
|
||||
return res?.data;
|
||||
}
|
||||
|
||||
static async get (id: number): Promise<any> {
|
||||
const res: AxiosResponse<any> = await apiClient.get(`/api/spaces/${id}`);
|
||||
static async get (id: number): Promise<Space> {
|
||||
const res: AxiosResponse<Space> = await apiClient.get(`/api/spaces/${id}`);
|
||||
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.
|
||||
* 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 }) => {
|
||||
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 => {
|
||||
return <CreateExtendedPrice onSuccess={handleSuccess}
|
||||
@ -57,7 +57,7 @@ export const ConfigureExtendedPriceButton: React.FC<ConfigureExtendedPriceButton
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="configure-packs-button">
|
||||
<div className="configure-extended-prices-button">
|
||||
<button className="packs-button" onClick={toggleShowList}>
|
||||
<i className="fas fa-stopwatch" />
|
||||
</button>
|
||||
|
@ -24,7 +24,7 @@ export const CreateExtendedPrice: React.FC<CreateExtendedPriceProps> = ({ onSucc
|
||||
const [isOpen, setIsOpen] = useState<boolean>(false);
|
||||
|
||||
/**
|
||||
* Open/closes the "new pack" modal dialog
|
||||
* Open/closes the "new extended price" modal dialog
|
||||
*/
|
||||
const toggleModal = (): void => {
|
||||
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
|
||||
*/
|
||||
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);
|
||||
newExtendedPrice.group_id = groupId;
|
||||
newExtendedPrice.priceable_id = priceableId;
|
||||
@ -58,11 +58,11 @@ export const CreateExtendedPrice: React.FC<CreateExtendedPriceProps> = ({ onSucc
|
||||
className="new-pack-modal"
|
||||
closeButton
|
||||
confirmButton={t('app.admin.create_extendedPrice.create_extendedPrice')}
|
||||
onConfirmSendFormId="new-pack">
|
||||
onConfirmSendFormId="new-extended-price">
|
||||
<FabAlert level="info">
|
||||
{t('app.admin.create_extendedPrice.new_extendedPrice_info', { TYPE: priceableType })}
|
||||
</FabAlert>
|
||||
<ExtendedPriceForm formId="new-pack" onSubmit={handleSubmit} />
|
||||
<ExtendedPriceForm formId="new-extended-price" onSubmit={handleSubmit} />
|
||||
</FabModal>
|
||||
</div>
|
||||
);
|
||||
|
@ -59,7 +59,7 @@ export const ExtendedPriceForm: React.FC<PackFormProps> = ({ formId, onSubmit, p
|
||||
min={1}
|
||||
icon={<i className="fas fa-clock" />}
|
||||
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"
|
||||
type="number"
|
||||
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 => {
|
||||
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);
|
||||
};
|
||||
|
||||
@ -90,7 +94,7 @@ const SpacesPricing: React.FC<SpacesPricingProps> = ({ onError, onSuccess }) =>
|
||||
const handleUpdatePrice = (price: Price): void => {
|
||||
PriceAPI.update(price)
|
||||
.then(() => {
|
||||
onSuccess(t('app.admin.machines_pricing.price_updated'));
|
||||
onSuccess(t('app.admin.spaces_pricing.price_updated'));
|
||||
updatePrice(price);
|
||||
})
|
||||
.catch(error => onError(error));
|
||||
@ -116,7 +120,7 @@ const SpacesPricing: React.FC<SpacesPricingProps> = ({ onError, onSuccess }) =>
|
||||
{groups?.map(group => <td key={group.id}>
|
||||
{prices && <EditablePrice price={findPriceBy(space.id, group.id)} onSave={handleUpdatePrice} />}
|
||||
<ConfigureExtendedPriceButton
|
||||
prices={findPricesBy(space.id, group.id)}
|
||||
prices={findExtendedPricesBy(space.id, group.id)}
|
||||
onError={onError}
|
||||
onSuccess={onSuccess}
|
||||
groupId={group.id}
|
||||
|
@ -368,6 +368,8 @@ en:
|
||||
status_enabled: "Enabled"
|
||||
status_disabled: "Disabled"
|
||||
status_all: "All"
|
||||
spaces_pricing:
|
||||
price_updated: "Price successfully updated"
|
||||
machines_pricing:
|
||||
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>."
|
||||
@ -381,6 +383,8 @@ en:
|
||||
configure_extendedPrices_button:
|
||||
extendedPrices: "Extended prices"
|
||||
no_extendedPrices: "No extended price for now"
|
||||
extended_prices_form:
|
||||
amount: "Price"
|
||||
pack_form:
|
||||
hours: "Hours"
|
||||
amount: "Price"
|
||||
@ -409,7 +413,7 @@ en:
|
||||
pack_successfully_updated: "The prepaid pack was successfully updated."
|
||||
create_extendedPrice:
|
||||
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"
|
||||
extendedPrice_successfully_created: "The new extended price was successfully created."
|
||||
delete_extendedPrice:
|
||||
|
Loading…
Reference in New Issue
Block a user