8000 refactor: Storage Keys Redux Slice for storing local storage data by sujitaw · Pull Request #970 · credebl/studio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

refactor: Storage Keys Redux Slice for storing local storage data #970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions nextjs/src/lib/storageKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { PayloadAction, createSlice } from '@reduxjs/toolkit'

import { SelectedUsers } from '@/features/organization/connectionIssuance/type/Issuance'

interface AuthState {
W3C_SCHEMA_DATA?: W3cSchemaDetails | undefined
W3C_SCHEMA_DETAILS?: W3cSchemaDetails
ALL_SCHEMAS?: string
ORG_DID?: string
SCHEMA_ATTR?: SchemaDetails
SCHEMA_ID?: string
CRED_DEF_ID?: string
SELECTED_CONNECTIONS?: LocalOrgs[]
SELECTED_USER?: SelectedUsers[] | SelectedUsersString[]
}
interface SelectedUsersString {
userName: string
connectionId: string
}

const initialState: AuthState = {
W3C_SCHEMA_DATA: {
schemaId: '',
schemaName: '',
version: '',
issuerDid: '',
attributes: [],
created: '',
},
}
interface W3cSchemaDetails {
schemaId: string
schemaName: string
version: string
issuerDid: string
attributes: []
created: string
}
export interface SchemaDetails {
attribute: string[]
issuerDid: string
createdDate: string
schemaName?: string
version?: string
schemaId?: string
}

type LocalOrgs = {
connectionId: string
theirLabel: string
createDateTime: string
}

const storageKeys = createSlice({
name: 'storageKeys',
initialState,
reducers: {
setW3cSchemaData: (state, action: PayloadAction<W3cSchemaDetails>) => {
state.W3C_SCHEMA_DATA = action.payload
},
setSchemaDetails: (state, action: PayloadAction<W3cSchemaDetails>) => {
state.W3C_SCHEMA_DETAILS = action.payload
},
setAllSchema: (state, action: PayloadAction<string>) => {
state.ALL_SCHEMAS = action.payload
},
setOrgDid: (state, action: PayloadAction<string>) => {
state.ORG_DID = action.payload
},
setSchemaAttr: (state, action: PayloadAction<SchemaDetails>) => {
state.SCHEMA_ATTR = action.payload
},
setSchemaId: (state, action: PayloadAction<string>) => {
state.SCHEMA_ID = action.payload
},
setCredDefId: (state, action: PayloadAction<string>) => {
state.CRED_DEF_ID = action.payload
},
setSelectedConnection: (state, action: PayloadAction<LocalOrgs[]>) => {
state.SELECTED_CONNECTIONS = action.payload
},
clearSelectedConnection: (state) => {
state.SELECTED_CONNECTIONS = []
},
clearSelectedUser: (state) => {
state.SELECTED_USER = []
},
setSelectedUser: (state, action: PayloadAction<SelectedUsers[]>) => {
state.SELECTED_USER = action.payload
},
clearStorage: () => initialState,
},
})

export const {
clearSelectedUser,
setSelectedUser,
setW3cSchemaData,
setSchemaDetails,
setAllSchema,
setOrgDid,
setCredDefId,
setSchemaAttr,
setSchemaId,
clearStorage,
setSelectedConnection,
clearSelectedConnection,
} = storageKeys.actions
export default storageKeys.reducer
11 changes: 10 additions & 1 deletion nextjs/src/lib/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,30 @@ import authSlice from './authSlice'
import orgSlice from './orgSlice'
import profileSlice from './profileSlice'
import storage from 'redux-persist/lib/storage'
import storageReducer from './storageKeys'
import userSlice from './userSlice'
import walletSpinupSlice from './walletSpinupSlice'

const rootReducer = combineReducers({
auth: authSlice,
profile: profileSlice,
organization: orgSlice,
storageKeys: storageReducer,
user: userSlice,
wallet: walletSpinupSlice,
})

const persistConfig = {
key: 'root',
storage,
whitelist: ['auth', 'profile', 'organization', 'user', 'wallet'],
whitelist: [
'auth',
'profile',
'organization',
'storageKeys',
'user',
'wallet',
],
}

const persistedReducer = persistReducer(persistConfig, rootReducer)
Expand Down
0