28 lines
889 B
JavaScript
28 lines
889 B
JavaScript
import { ITEM_PLACEMENTS } from '../constants';
|
|
|
|
export function toPlacementFormState(rawPlacement = 'suitcase') {
|
|
const placement = `${rawPlacement || ''}`.trim() || 'suitcase';
|
|
const hasPresetPlacement = ITEM_PLACEMENTS.includes(placement);
|
|
|
|
return {
|
|
placement: hasPresetPlacement ? placement : 'other',
|
|
placementCustom: hasPresetPlacement || placement === 'other' ? '' : placement,
|
|
};
|
|
}
|
|
|
|
export function resolvePlacementValue(placement = '', placementCustom = '') {
|
|
const normalizedPlacement = `${placement || ''}`.trim();
|
|
if (!normalizedPlacement) return '';
|
|
|
|
if (normalizedPlacement === 'other') {
|
|
return `${placementCustom || ''}`.trim();
|
|
}
|
|
|
|
return normalizedPlacement;
|
|
}
|
|
|
|
export function withPlacementCustomFallback(currentCustom = '', fallback = '') {
|
|
const custom = `${currentCustom || ''}`.trim();
|
|
return custom || `${fallback || ''}`.trim();
|
|
}
|