From b073498beb44464e5541aa06088ba0ed998d134d Mon Sep 17 00:00:00 2001 From: Johny Ho Date: Wed, 16 Oct 2024 07:46:46 -0400 Subject: [PATCH] Update flash.js This gives a slice some new functionality based on the needs of existing projects. --- .../lib/install/templates/web/flash.js | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/superglue_rails/lib/install/templates/web/flash.js b/superglue_rails/lib/install/templates/web/flash.js index 2d432abd..3b6ff947 100644 --- a/superglue_rails/lib/install/templates/web/flash.js +++ b/superglue_rails/lib/install/templates/web/flash.js @@ -1,19 +1,32 @@ -import { createSlice } from '@reduxjs/toolkit' +import { createSlice } from '@reduxjs/toolkit'; import { saveResponse, beforeVisit } from '@thoughtbot/superglue' export const flashSlice = createSlice({ name: 'flash', initialState: {}, + reducers: { + clearFlash() { + return {}; + }, + flash(state, { payload }) { + return payload; + }, + }, extraReducers: (builder) => { builder.addCase(beforeVisit, (state, action) => { - return {} - }) + return {}; + }); builder.addCase(saveResponse, (state, action) => { const { page } = action.payload; return { - ...state, ...page.slices.flash - } - }) - } -}) + ...state, + ...page.slices.flash, + }; + }); + }, +}); + +export const { clearFlash, flash } = flashSlice.actions; + +