Skip to content

Commit

Permalink
chore: feature toggle handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hoeppner-dataport committed Apr 12, 2024
1 parent 8e0b559 commit fc23014
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
37 changes: 14 additions & 23 deletions src/modules/data/board/BoardStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,21 @@ export const useBoardStore = defineStore("boardStore", () => {
(typeof BoardActions)[keyof typeof BoardActions]
>["payload"];

const emit = (
action: PermittedStoreActions<typeof BoardActions> | any,
payload: AnyBoardActionPayload
) => {
if (FEATURE_SOCKET_ENABLED) return emitOnSocket(action.type, payload);
const emitOnSocketWrapper = (action: {
type: string;
payload: AnyBoardActionPayload;
}) => {
if (FEATURE_SOCKET_ENABLED) {
emitOnSocket(action.type, action.payload);
return true;
}
};

async function dispatch(action: PermittedStoreActions<typeof BoardActions>) {
handle(
action,
on(BoardActions.fetchBoard, fetchBoard),
on(BoardActions.createCardRequest, createCard),
on(BoardActions.createCardRequest, emitOnSocketWrapper ?? createCard),
on(BoardActions.createCardSuccess, createCardSuccess),
on(BoardActions.createColumn, createColumn),
on(BoardActions.createColumnSuccess, createColumnSuccess),
Expand Down Expand Up @@ -101,16 +104,15 @@ export const useBoardStore = defineStore("boardStore", () => {
const payload = {
newCard,
columnId: action.payload.columnId,
true: true,
};

dispatch(BoardActions.createCardSuccess(payload));

emit(action, payload);
} catch (error) {
handleError(error, {
404: notifyWithTemplateAndReload("notCreated", "boardCard"),
});
dispatch(
BoardActions.createCardFailure({
errorMessage: "unable to create card",
})
);
}
};

Expand Down Expand Up @@ -138,14 +140,7 @@ export const useBoardStore = defineStore("boardStore", () => {

try {
const newColumn: ColumnResponse = await createColumnCall(board.value.id);

const payload = {
type: "create-column",
payload: newColumn,
};

dispatch(BoardActions.createColumnSuccess({ newColumn }));
emit(payload, newColumn);
return newColumn;
} catch (error) {
handleError(error, {
Expand All @@ -172,7 +167,6 @@ export const useBoardStore = defineStore("boardStore", () => {
try {
await deleteCardCall(cardId);
dispatch(BoardActions.deleteCardSuccess({ cardId }));
emit(action, { cardId });
} catch (error) {
handleError(error, {
404: notifyWithTemplateAndReload("notDeleted", "boardCard"),
Expand Down Expand Up @@ -206,7 +200,6 @@ export const useBoardStore = defineStore("boardStore", () => {
await deleteColumnCall(columnId);

dispatch(BoardActions.deleteColumnSuccess({ columnId }));
emit(action, { columnId });
} catch (error) {
handleError(error, {
404: notifyWithTemplateAndReload("notDeleted", "boardColumn"),
Expand Down Expand Up @@ -315,7 +308,6 @@ export const useBoardStore = defineStore("boardStore", () => {

await moveColumnCall(columnId, board.value.id, addedIndex);
dispatch(BoardActions.moveColumnSuccess(action.payload));
emit(action, action.payload);
} catch (error) {
handleError(error, {
404: notifyWithTemplateAndReload("notUpdated", "boardColumn"),
Expand Down Expand Up @@ -356,7 +348,6 @@ export const useBoardStore = defineStore("boardStore", () => {
await updateColumnTitleCall(columnId, newTitle);

dispatch(BoardActions.updateColumnTitleSuccess(action.payload));
emit(action, action.payload);
} catch (error) {
handleError(error, {
404: notifyWithTemplateAndReload("notUpdated", "boardColumn"),
Expand Down
10 changes: 8 additions & 2 deletions src/modules/data/board/actions/BoardStoreActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const getColumnId = createAction(
);

const createCardRequest = createAction(
"create-card",
"create-card-request",
props<{ columnId: string }>()
);

Expand All @@ -26,6 +26,11 @@ const createCardSuccess = createAction(
props<{ newCard: CardResponse; columnId: string }>()
);

const createCardFailure = createAction(
"create-card-failure",
props<{ errorMessage: string }>()
);

const createColumn = createAction("create-column", props());
const createColumnSuccess = createAction(
"create-column-success",
Expand Down Expand Up @@ -94,9 +99,10 @@ export {
getColumnId,
createCardRequest,
createCardSuccess,
createCardFailure,
deleteCard,
createColumn,
createColumnSuccess,
deleteCard,
deleteCardSuccess,
deleteColumn,
deleteColumnSuccess,
Expand Down

0 comments on commit fc23014

Please sign in to comment.