import { createSlice } from '@reduxjs/toolkit';

export const EditSecretUISlice = createSlice({
  name: 'EditSecretUI',
  initialState: {
    isEditing: false,
    data: null,
  },
  reducers: {
    updateSecret: (state, action) => {
      state.isEditing = false;
      state.data = action.payload.secret.data;
    },
    updateData: (state, action) => {
      state.isEditing = false;
      state.data = action.payload.data;
    },
    hideModal: (state, action) => {
      state.isEditing = false;
      state.data = null;
    },
    changeField: (state, action) => {
      const { field, value } = action.payload;
      state.isEditing = true;
      // TODO : this is probably broken, check actual structure of the metadata
      const fieldIndex = state.data.fields.findIndex(
        fieldToUpdate => fieldToUpdate.id === field.id
      );
      state.data.fields[fieldIndex] = value;
    },
  },
});

// Action creators are generated for each case reducer function
export const {
  updateSecret,
  updateData,
  hideModal,
  changeField,
} = EditSecretUISlice.actions;

export default EditSecretUISlice.reducer;

@@ -42,16 +42,79 @@
 lkit';%0A%0A
+import %7B showSecretSuccess %7D from 'slices/ShowSecretUISlice';%0A%0A
 export c
@@ -255,132 +255,8 @@
 : %7B%0A
-    updateSecret: (state, action) =%3E %7B%0A      state.isEditing = false;%0A      state.data = action.payload.secret.data;%0A    %7D,%0A
     
@@ -835,16 +835,171 @@
 %7D,%0A  %7D,%0A
+  extraReducers: %7B%0A    %5BshowSecretSuccess%5D: (state, action) =%3E %7B%0A      state.isEditing = false;%0A      state.data = action.payload.secret.data;%0A    %7D,%0A  %7D,%0A
 %7D);%0A%0A// 
@@ -1077,26 +1077,8 @@
 st %7B
-%0A  updateSecret,%0A 
  upd
@@ -1085,18 +1085,16 @@
 ateData,
-%0A 
  hideMod
@@ -1096,18 +1096,16 @@
 deModal,
-%0A 
  changeF
@@ -1108,18 +1108,17 @@
 ngeField
-,%0A
+ 
 %7D = Edit

fix rendering of secret fields