Files
klz-cables.com/.pnpm-store/v10/files/40/d50e956cde5739626aab8e0bf08f13629192047176e856c30e81efbe0ec7b76c04d8ce7716b983b061ff553ce31929e2e2688c0c2d978c52f0b9fc621afd62
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

94 lines
2.8 KiB
Plaintext

import { v4 as uuidv4 } from 'uuid';
export function formsManagementReducer(state, action) {
switch (action.type) {
case 'ADD_FORMS':
{
const newForms = [];
for (let i = 0; i < action.forms.length; i++) {
newForms[i] = {
errorCount: 0,
formID: action.forms[i].formID ?? (crypto.randomUUID ? crypto.randomUUID() : uuidv4()),
formState: {
...(action.forms[i].initialState || {}),
file: {
initialValue: action.forms[i].file,
valid: true,
value: action.forms[i].file
}
},
uploadEdits: {}
};
}
return {
...state,
activeIndex: 0,
forms: [...newForms, ...state.forms]
};
}
case 'REMOVE_FORM':
{
const remainingFormStates = [...state.forms];
const [removedForm] = remainingFormStates.splice(action.index, 1);
const affectedByShift = state.activeIndex >= action.index;
const nextIndex = state.activeIndex === action.index ? action.index : affectedByShift ? state.activeIndex - 1 : state.activeIndex;
const boundedActiveIndex = Math.min(remainingFormStates.length - 1, nextIndex);
return {
...state,
activeIndex: affectedByShift ? boundedActiveIndex : state.activeIndex,
forms: remainingFormStates,
totalErrorCount: state.totalErrorCount - removedForm.errorCount
};
}
case 'REPLACE':
{
return {
...state,
...action.state
};
}
case 'SET_ACTIVE_INDEX':
{
return {
...state,
activeIndex: action.index
};
}
case 'UPDATE_ERROR_COUNT':
{
const forms = [...state.forms];
forms[action.index].errorCount = action.count;
return {
...state,
forms,
totalErrorCount: forms.reduce((acc, form) => acc + form.errorCount, 0)
};
}
case 'UPDATE_FORM':
{
const updatedForms = [...state.forms];
updatedForms[action.index].errorCount = action.errorCount;
// Merge the existing formState with the new formState
updatedForms[action.index] = {
...updatedForms[action.index],
formState: {
...updatedForms[action.index].formState,
...action.formState
},
uploadEdits: {
...updatedForms[action.index].uploadEdits,
...action.uploadEdits
}
};
return {
...state,
forms: updatedForms,
totalErrorCount: updatedForms.reduce((acc, form) => acc + form.errorCount, 0)
};
}
default:
{
return state;
}
}
}
//# sourceMappingURL=reducer.js.map