diff --git a/app/frontend/src/javascript/components/dashboard/orders/orders-dashboard.tsx b/app/frontend/src/javascript/components/dashboard/orders/orders-dashboard.tsx index c57a1c858..652d05306 100644 --- a/app/frontend/src/javascript/components/dashboard/orders/orders-dashboard.tsx +++ b/app/frontend/src/javascript/components/dashboard/orders/orders-dashboard.tsx @@ -9,6 +9,7 @@ import { FabPagination } from '../../base/fab-pagination'; import OrderAPI from '../../../api/order'; import { Order, OrderSortOption } from '../../../models/order'; import { User } from '../../../models/user'; +import { SelectOption } from '../../../models/select'; declare const Application: IApplication; @@ -16,11 +17,6 @@ interface OrdersDashboardProps { currentUser: User, onError: (message: string) => void } -/** -* Option format, expected by react-select -* @see https://github.com/JedWatson/react-select -*/ -type selectOption = { value: OrderSortOption, label: string }; /** * This component shows a list of all orders from the store for the current user @@ -44,7 +40,7 @@ export const OrdersDashboard: React.FC = ({ currentUser, o /** * Creates sorting options to the react-select format */ - const buildOptions = (): Array => { + const buildOptions = (): Array> => { return [ { value: 'created_at-desc', label: t('app.public.orders_dashboard.sort.newest') }, { value: 'created_at-asc', label: t('app.public.orders_dashboard.sort.oldest') } @@ -53,7 +49,7 @@ export const OrdersDashboard: React.FC = ({ currentUser, o /** * Display option: sorting */ - const handleSorting = (option: selectOption) => { + const handleSorting = (option: SelectOption) => { OrderAPI.index({ page: 1, sort: option.value }).then(res => { setCurrentPage(1); setOrders(res.data); diff --git a/app/frontend/src/javascript/components/events/event-themes.tsx b/app/frontend/src/javascript/components/events/event-themes.tsx index 1c4d4eae2..473c6e887 100644 --- a/app/frontend/src/javascript/components/events/event-themes.tsx +++ b/app/frontend/src/javascript/components/events/event-themes.tsx @@ -7,6 +7,7 @@ import { Event } from '../../models/event'; import { EventTheme } from '../../models/event-theme'; import { IApplication } from '../../models/application'; import EventThemeAPI from '../../api/event-theme'; +import { SelectOption } from '../../models/select'; declare const Application: IApplication; @@ -15,12 +16,6 @@ interface EventThemesProps { onChange: (themes: Array) => void } -/** - * Option format, expected by react-select - * @see https://github.com/JedWatson/react-select - */ -type selectOption = { value: number, label: string }; - /** * This component shows a select input to edit the themes associated with the event */ @@ -43,7 +38,7 @@ export const EventThemes: React.FC = ({ event, onChange }) => /** * Return the current theme(s) for the given event, formatted to match the react-select format */ - const defaultValues = (): Array => { + const defaultValues = (): Array> => { const res = []; themes.forEach(t => { if (event.event_theme_ids && event.event_theme_ids.indexOf(t.id) > -1) { @@ -57,7 +52,7 @@ export const EventThemes: React.FC = ({ event, onChange }) => * Callback triggered when the selection has changed. * Convert the react-select specific format to an array of EventTheme, and call the provided callback. */ - const handleChange = (selectedOptions: Array): void => { + const handleChange = (selectedOptions: Array>): void => { const res = []; selectedOptions.forEach(opt => { res.push(themes.find(t => t.id === opt.value)); @@ -68,7 +63,7 @@ export const EventThemes: React.FC = ({ event, onChange }) => /** * Convert all themes to the react-select format */ - const buildOptions = (): Array => { + const buildOptions = (): Array> => { return themes.map(t => { return { value: t.id, label: t.name }; }); diff --git a/app/frontend/src/javascript/components/form/form-checklist.tsx b/app/frontend/src/javascript/components/form/form-checklist.tsx index 0d8d6e4ee..b5cc8d8a2 100644 --- a/app/frontend/src/javascript/components/form/form-checklist.tsx +++ b/app/frontend/src/javascript/components/form/form-checklist.tsx @@ -7,11 +7,7 @@ import { UnpackNestedValue } from 'react-hook-form/dist/types'; import { FormControlledComponent } from '../../models/form-component'; import { AbstractFormItem, AbstractFormItemProps } from './abstract-form-item'; import { FabButton } from '../base/fab-button'; - -/** - * Checklist Option format - */ -export type ChecklistOption = { value: TOptionValue, label: string }; +import { ChecklistOption } from '../../models/select'; interface FormChecklistProps extends FormControlledComponent, AbstractFormItemProps { defaultValue?: Array, diff --git a/app/frontend/src/javascript/components/form/form-select.tsx b/app/frontend/src/javascript/components/form/form-select.tsx index 82e42be34..208170544 100644 --- a/app/frontend/src/javascript/components/form/form-select.tsx +++ b/app/frontend/src/javascript/components/form/form-select.tsx @@ -7,9 +7,10 @@ import { FieldPath } from 'react-hook-form/dist/types/path'; import { FieldPathValue, UnpackNestedValue } from 'react-hook-form/dist/types'; import { FormControlledComponent } from '../../models/form-component'; import { AbstractFormItem, AbstractFormItemProps } from './abstract-form-item'; +import { SelectOption } from '../../models/select'; -interface FormSelectProps extends FormControlledComponent, AbstractFormItemProps { - options: Array>, +interface FormSelectProps extends FormControlledComponent, AbstractFormItemProps { + options: Array>, valueDefault?: TOptionValue, onChange?: (value: TOptionValue) => void, placeholder?: string, @@ -17,16 +18,10 @@ interface FormSelectProps e creatable?: boolean, } -/** - * Option format, expected by react-select - * @see https://github.com/JedWatson/react-select - */ -type selectOption = { value: TOptionValue, label: string }; - /** * This component is a wrapper for react-select to use with react-hook-form */ -export const FormSelect = ({ id, label, tooltip, className, control, placeholder, options, valueDefault, error, warning, rules, disabled = false, onChange, clearable = false, formState, creatable = false }: FormSelectProps) => { +export const FormSelect = ({ id, label, tooltip, className, control, placeholder, options, valueDefault, error, warning, rules, disabled = false, onChange, clearable = false, formState, creatable = false }: FormSelectProps) => { const [isDisabled, setIsDisabled] = React.useState(false); useEffect(() => { diff --git a/app/frontend/src/javascript/components/group/change-group.tsx b/app/frontend/src/javascript/components/group/change-group.tsx index 653f65931..86e9f2d6a 100644 --- a/app/frontend/src/javascript/components/group/change-group.tsx +++ b/app/frontend/src/javascript/components/group/change-group.tsx @@ -12,6 +12,7 @@ import { FormSelect } from '../form/form-select'; import MemberAPI from '../../api/member'; import SettingAPI from '../../api/setting'; import UserLib from '../../lib/user'; +import { SelectOption } from '../../models/select'; declare const Application: IApplication; @@ -23,12 +24,6 @@ interface ChangeGroupProps { className?: string, } -/** - * Option format, expected by react-select - * @see https://github.com/JedWatson/react-select - */ -type selectOption = { value: number, label: string }; - /** * Component to display the group of the provided user, and allow him to change his group. */ @@ -72,7 +67,7 @@ export const ChangeGroup: React.FC = ({ user, onSuccess, onErr /** * Convert the provided array of items to the react-select format */ - const buildGroupsOptions = (): Array => { + const buildGroupsOptions = (): Array> => { return groups?.map(t => { return { value: t.id, label: t.name }; }); diff --git a/app/frontend/src/javascript/components/machines/machines-filters.tsx b/app/frontend/src/javascript/components/machines/machines-filters.tsx index 747050b41..c1218c15f 100644 --- a/app/frontend/src/javascript/components/machines/machines-filters.tsx +++ b/app/frontend/src/javascript/components/machines/machines-filters.tsx @@ -1,17 +1,12 @@ import React from 'react'; import Select from 'react-select'; import { useTranslation } from 'react-i18next'; +import { SelectOption } from '../../models/select'; interface MachinesFiltersProps { onStatusSelected: (enabled: boolean) => void, } -/** - * Option format, expected by react-select - * @see https://github.com/JedWatson/react-select - */ -type selectOption = { value: boolean, label: string }; - /** * Allows filtering on machines list */ @@ -23,7 +18,7 @@ export const MachinesFilters: React.FC = ({ onStatusSelect /** * Provides boolean options in the react-select format (yes/no/all) */ - const buildBooleanOptions = (): Array => { + const buildBooleanOptions = (): Array> => { return [ defaultValue, { value: false, label: t('app.public.machines_filters.status_disabled') }, @@ -34,7 +29,7 @@ export const MachinesFilters: React.FC = ({ onStatusSelect /** * Callback triggered when the user selects a machine status in the dropdown list */ - const handleStatusSelected = (option: selectOption): void => { + const handleStatusSelected = (option: SelectOption): void => { onStatusSelected(option.value); }; diff --git a/app/frontend/src/javascript/components/payment-schedule/update-payment-mean-modal.tsx b/app/frontend/src/javascript/components/payment-schedule/update-payment-mean-modal.tsx index e051191b2..7e95b80ce 100644 --- a/app/frontend/src/javascript/components/payment-schedule/update-payment-mean-modal.tsx +++ b/app/frontend/src/javascript/components/payment-schedule/update-payment-mean-modal.tsx @@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next'; import { FabModal } from '../base/fab-modal'; import { PaymentMethod, PaymentSchedule } from '../../models/payment-schedule'; import PaymentScheduleAPI from '../../api/payment-schedule'; +import { SelectOption } from '../../models/select'; interface UpdatePaymentMeanModalProps { isOpen: boolean, @@ -13,12 +14,6 @@ interface UpdatePaymentMeanModalProps { paymentSchedule: PaymentSchedule } -/** - * Option format, expected by react-select - * @see https://github.com/JedWatson/react-select - */ -type selectOption = { value: PaymentMethod, label: string }; - /** * Component to allow the member to change his payment mean for the given payment schedule (e.g. from card to transfer) */ @@ -30,7 +25,7 @@ export const UpdatePaymentMeanModal: React.FC = ({ /** * Convert all payment means to the react-select format */ - const buildOptions = (): Array => { + const buildOptions = (): Array> => { return Object.keys(PaymentMethod).filter(pm => PaymentMethod[pm] !== PaymentMethod.Card).map(pm => { return { value: PaymentMethod[pm], label: t(`app.admin.update_payment_mean_modal.method_${pm}`) }; }); @@ -39,7 +34,7 @@ export const UpdatePaymentMeanModal: React.FC = ({ /** * When the payment mean is changed in the select, update the state */ - const handleMeanSelected = (option: selectOption): void => { + const handleMeanSelected = (option: SelectOption): void => { setPaymentMean(option.value); }; diff --git a/app/frontend/src/javascript/components/payment/local-payment/local-payment-form.tsx b/app/frontend/src/javascript/components/payment/local-payment/local-payment-form.tsx index 1a78166fa..cf612adfd 100644 --- a/app/frontend/src/javascript/components/payment/local-payment/local-payment-form.tsx +++ b/app/frontend/src/javascript/components/payment/local-payment/local-payment-form.tsx @@ -9,16 +9,11 @@ import { CardPaymentModal } from '../card-payment-modal'; import { PaymentSchedule } from '../../../models/payment-schedule'; import { HtmlTranslate } from '../../base/html-translate'; import CheckoutAPI from '../../../api/checkout'; +import { SelectOption } from '../../../models/select'; const ALL_SCHEDULE_METHODS = ['card', 'check', 'transfer'] as const; type scheduleMethod = typeof ALL_SCHEDULE_METHODS[number]; -/** - * Option format, expected by react-select - * @see https://github.com/JedWatson/react-select - */ -type selectOption = { value: scheduleMethod, label: string }; - /** * A form component to ask for confirmation before cashing a payment directly at the FabLab's reception. * This is intended for use by privileged users. @@ -44,14 +39,14 @@ export const LocalPaymentForm: React.FC = ({ onSubmit, onSucce /** * Convert all payement methods for schedules to the react-select format */ - const buildMethodOptions = (): Array => { + const buildMethodOptions = (): Array> => { return ALL_SCHEDULE_METHODS.map(i => methodToOption(i)); }; /** * Convert the given payment-method to the react-select format */ - const methodToOption = (value: scheduleMethod): selectOption => { + const methodToOption = (value: scheduleMethod): SelectOption => { if (!value) return { value, label: '' }; return { value, label: t(`app.admin.local_payment_form.method_${value}`) }; @@ -60,7 +55,7 @@ export const LocalPaymentForm: React.FC = ({ onSubmit, onSucce /** * Callback triggered when the user selects a payment method for the current payment schedule. */ - const handleUpdateMethod = (option: selectOption) => { + const handleUpdateMethod = (option: SelectOption) => { updateCart(Object.assign({}, cart, { payment_method: option.value })); setMethod(option.value); }; diff --git a/app/frontend/src/javascript/components/plans/plans-filter.tsx b/app/frontend/src/javascript/components/plans/plans-filter.tsx index 8a280bd62..a71be0cd6 100644 --- a/app/frontend/src/javascript/components/plans/plans-filter.tsx +++ b/app/frontend/src/javascript/components/plans/plans-filter.tsx @@ -5,6 +5,7 @@ import { Group } from '../../models/group'; import { User } from '../../models/user'; import PlanAPI from '../../api/plan'; import { PlansDuration } from '../../models/plan'; +import { SelectOption } from '../../models/select'; interface PlansFilterProps { user?: User, @@ -14,12 +15,6 @@ interface PlansFilterProps { onDurationSelected: (plansIds: Array) => void, } -/** - * Option format, expected by react-select - * @see https://github.com/JedWatson/react-select - */ -type selectOption = { value: number, label: string }; - /** * Allows filtering on plans list */ @@ -38,7 +33,7 @@ export const PlansFilter: React.FC = ({ user, groups, onGroupS /** * Convert all groups to the react-select format */ - const buildGroupOptions = (): Array => { + const buildGroupOptions = (): Array> => { return groups.filter(g => !g.disabled && g.slug !== 'admins').map(g => { return { value: g.id, label: g.name }; }); @@ -47,7 +42,7 @@ export const PlansFilter: React.FC = ({ user, groups, onGroupS /** * Convert all durations to the react-select format */ - const buildDurationOptions = (): Array => { + const buildDurationOptions = (): Array> => { const options = durations.map((d, index) => { return { value: index, label: d.name }; }); @@ -58,14 +53,14 @@ export const PlansFilter: React.FC = ({ user, groups, onGroupS /** * Callback triggered when the user selects a group in the dropdown list */ - const handleGroupSelected = (option: selectOption): void => { + const handleGroupSelected = (option: SelectOption): void => { onGroupSelected(option.value); }; /** * Callback triggered when the user selects a duration in the dropdown list */ - const handleDurationSelected = (option: selectOption): void => { + const handleDurationSelected = (option: SelectOption): void => { onDurationSelected(durations[option.value]?.plans_ids); }; diff --git a/app/frontend/src/javascript/components/pricing/machines/pack-form.tsx b/app/frontend/src/javascript/components/pricing/machines/pack-form.tsx index ba4381c46..43c5b4820 100644 --- a/app/frontend/src/javascript/components/pricing/machines/pack-form.tsx +++ b/app/frontend/src/javascript/components/pricing/machines/pack-form.tsx @@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next'; import { useImmer } from 'use-immer'; import { FabInput } from '../../base/fab-input'; import { IFablab } from '../../../models/fablab'; +import { SelectOption } from '../../../models/select'; declare let Fablab: IFablab; @@ -18,12 +19,6 @@ interface PackFormProps { const ALL_INTERVALS = ['day', 'week', 'month', 'year'] as const; type interval = typeof ALL_INTERVALS[number]; -/** - * Option format, expected by react-select - * @see https://github.com/JedWatson/react-select - */ -type selectOption = { value: interval, label: string }; - /** * A form component to create/edit a PrepaidPack. * The form validation must be created elsewhere, using the attribute form={formId}. @@ -36,14 +31,14 @@ export const PackForm: React.FC = ({ formId, onSubmit, pack }) => /** * Convert all validity-intervals to the react-select format */ - const buildOptions = (): Array => { + const buildOptions = (): Array> => { return ALL_INTERVALS.map(i => intervalToOption(i)); }; /** * Convert the given validity-interval to the react-select format */ - const intervalToOption = (value: interval): selectOption => { + const intervalToOption = (value: interval): SelectOption => { if (!value) return { value, label: '' }; return { value, label: t(`app.admin.pack_form.intervals.${value}`, { COUNT: packData.validity_count || 0 }) }; @@ -87,7 +82,7 @@ export const PackForm: React.FC = ({ formId, onSubmit, pack }) => /** * Callback triggered when the user selects a type of interval for the current pack. */ - const handleUpdateValidityInterval = (option: selectOption) => { + const handleUpdateValidityInterval = (option: SelectOption) => { updatePackData(draft => { draft.validity_interval = option.value as interval; }); diff --git a/app/frontend/src/javascript/components/store/categories/product-category-form.tsx b/app/frontend/src/javascript/components/store/categories/product-category-form.tsx index 8b7541c1e..74fd0be03 100644 --- a/app/frontend/src/javascript/components/store/categories/product-category-form.tsx +++ b/app/frontend/src/javascript/components/store/categories/product-category-form.tsx @@ -8,6 +8,7 @@ import { ProductCategory } from '../../../models/product-category'; import { FabButton } from '../../base/fab-button'; import ProductCategoryAPI from '../../../api/product-category'; import { HtmlTranslate } from '../../base/html-translate'; +import { SelectOption } from '../../../models/select'; interface ProductCategoryFormProps { action: 'create' | 'update' | 'delete', @@ -17,12 +18,6 @@ interface ProductCategoryFormProps { onError: (message: string) => void, } -/** - * Option format, expected by react-select - * @see https://github.com/JedWatson/react-select - */ - type selectOption = { value: number, label: string }; - /** * Form to create/edit/delete a product category */ @@ -40,7 +35,7 @@ export const ProductCategoryForm: React.FC = ({ action /** * Convert all parents to the react-select format */ - const buildOptions = (): Array => { + const buildOptions = (): Array> => { const options = parents.map(t => { return { value: t.id, label: t.name }; }); diff --git a/app/frontend/src/javascript/components/store/filters/stock-filter.tsx b/app/frontend/src/javascript/components/store/filters/stock-filter.tsx index a7ec2903e..ba2497959 100644 --- a/app/frontend/src/javascript/components/store/filters/stock-filter.tsx +++ b/app/frontend/src/javascript/components/store/filters/stock-filter.tsx @@ -7,6 +7,7 @@ import { FormSelect } from '../../form/form-select'; import { FormInput } from '../../form/form-input'; import { useForm } from 'react-hook-form'; import _ from 'lodash'; +import { SelectOption } from '../../../models/select'; interface StockFilterProps { onApplyFilters: (filters: ProductIndexFilter) => void, @@ -14,12 +15,6 @@ interface StockFilterProps { openDefault?: boolean } -/** - * Option format, expected by react-select - * @see https://github.com/JedWatson/react-select - */ -type selectOption = { value: StockType, label: string }; - /** * Component to filter the products list by stock */ @@ -51,7 +46,7 @@ export const StockFilter: React.FC = ({ onApplyFilters, curren }; /** Creates sorting options to the react-select format */ - const buildStockOptions = (): Array => { + const buildStockOptions = (): Array> => { return [ { value: 'internal', label: t('app.admin.store.stock_filter.stock_internal') }, { value: 'external', label: t('app.admin.store.stock_filter.stock_external') } diff --git a/app/frontend/src/javascript/components/store/order-actions.tsx b/app/frontend/src/javascript/components/store/order-actions.tsx index 97f0137ec..a339fff2e 100644 --- a/app/frontend/src/javascript/components/store/order-actions.tsx +++ b/app/frontend/src/javascript/components/store/order-actions.tsx @@ -6,6 +6,7 @@ import OrderAPI from '../../api/order'; import { Order } from '../../models/order'; import FabTextEditor from '../base/text-editor/fab-text-editor'; import { HtmlTranslate } from '../base/html-translate'; +import { SelectOption } from '../../models/select'; interface OrderActionsProps { order: Order, @@ -13,18 +14,12 @@ interface OrderActionsProps { onError: (message: string) => void, } -/** -* Option format, expected by react-select -* @see https://github.com/JedWatson/react-select -*/ -type selectOption = { value: string, label: string }; - /** * Actions for an order */ export const OrderActions: React.FC = ({ order, onSuccess, onError }) => { const { t } = useTranslation('shared'); - const [currentAction, setCurrentAction] = useState(); + const [currentAction, setCurrentAction] = useState>(); const [modalIsOpen, setModalIsOpen] = useState(false); const [readyNote, setReadyNote] = useState(''); @@ -51,7 +46,7 @@ export const OrderActions: React.FC = ({ order, onSuccess, on /** * Creates sorting options to the react-select format */ - const buildOptions = (): Array => { + const buildOptions = (): Array> => { let actions = []; switch (order.state) { case 'paid': @@ -80,7 +75,7 @@ export const OrderActions: React.FC = ({ order, onSuccess, on /** * Callback after selecting an action */ - const handleAction = (action: selectOption) => { + const handleAction = (action: SelectOption) => { setCurrentAction(action); setModalIsOpen(true); }; diff --git a/app/frontend/src/javascript/components/store/orders.tsx b/app/frontend/src/javascript/components/store/orders.tsx index 0c1457dde..f0b1dca8d 100644 --- a/app/frontend/src/javascript/components/store/orders.tsx +++ b/app/frontend/src/javascript/components/store/orders.tsx @@ -16,6 +16,7 @@ import OrderAPI from '../../api/order'; import { Order, OrderIndexFilter, OrderSortOption } from '../../models/order'; import { FabPagination } from '../base/fab-pagination'; import { CaretDoubleUp, X } from 'phosphor-react'; +import { ChecklistOption, SelectOption } from '../../models/select'; declare const Application: IApplication; @@ -23,16 +24,6 @@ interface OrdersProps { currentUser?: User, onError: (message: string) => void, } -/** -* Option format, expected by react-select -* @see https://github.com/JedWatson/react-select -*/ -type selectOption = { value: OrderSortOption, label: string }; - -/** -* Option format, expected by checklist -*/ -type checklistOption = { value: string, label: string }; const initFilters: OrderIndexFilter = { reference: '', @@ -72,14 +63,7 @@ const Orders: React.FC = ({ currentUser, onError }) => { }).catch(onError); }, [filters]); - /** - * Create a new order - */ - const newOrder = () => { - console.log('Create new order'); - }; - - const statusOptions: checklistOption[] = [ + const statusOptions: ChecklistOption[] = [ { value: 'cart', label: t('app.admin.store.orders.state.cart') }, { value: 'paid', label: t('app.admin.store.orders.state.paid') }, { value: 'payment_failed', label: t('app.admin.store.orders.state.payment_failed') }, @@ -174,7 +158,7 @@ const Orders: React.FC = ({ currentUser, onError }) => { /** * Creates sorting options to the react-select format */ - const buildOptions = (): Array => { + const buildOptions = (): Array> => { return [ { value: 'created_at-desc', label: t('app.admin.store.orders.sort.newest') }, { value: 'created_at-asc', label: t('app.admin.store.orders.sort.oldest') } @@ -184,7 +168,7 @@ const Orders: React.FC = ({ currentUser, onError }) => { /** * Display option: sorting */ - const handleSorting = (option: selectOption) => { + const handleSorting = (option: SelectOption) => { setFilters(draft => { draft.sort = option.value; }); @@ -200,7 +184,7 @@ const Orders: React.FC = ({ currentUser, onError }) => { /** * Filter: by status */ - const handleSelectStatus = (s: checklistOption, checked: boolean) => { + const handleSelectStatus = (s: ChecklistOption, checked: boolean) => { const list = [...states]; checked ? list.push(s.value) @@ -250,11 +234,6 @@ const Orders: React.FC = ({ currentUser, onError }) => {

{t('app.admin.store.orders.heading')}

- {false && -
- {t('app.admin.store.orders.create_order')} -
- }