-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
slice.js
84 lines (81 loc) · 2.41 KB
/
slice.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { createSlice } from '@reduxjs/toolkit';
import { getUserBuckets } from './services/getBuckets';
const slice = createSlice({
name: 'GUI',
initialState: {
isMigrating: false,
origin: {
name: '',
accessId: '',
secretKey: '',
accountId: '',
selectedBucket: '',
service: '',
bucketOptions: ['one', 'two'],
},
destination: {
name: '',
secretKey: '',
accessId: '',
accountId: '',
selectedBucket: '',
service: '',
bucketOptions: ['one', 'two'],
},
},
reducers: {
migrationStatusChange: (state, action) => {
state.isMigrating = action.payload;
},
updateDestinationBasedOnOrigin: (state, action) => {
if (state.origin.name) state.destination = action.payload.destination;
},
updateDestinationCredentials: (state, action) => {
state.destination = action.payload.destination;
},
updateOriginAccessId: (state, action) => {
state.origin = action.payload.origin;
state.destination = action.payload.destination;
},
updateOriginSecretKey: (state, action) => {
state.origin = action.payload.origin;
},
updateDestinationAccessId: (state, action) => {
state.destination = action.payload.destination;
},
updateDestinationSecretKey: (state, action) => {
state.destination = action.payload.destination;
},
updateAccountId: (state, action) => {
const { origin, destination } = action.payload;
state.origin = origin;
state.destination = destination;
},
updateOriginBuckets: (state, action) => {
state.origin.buckets = action.payload;
} updateSelectedBucket: (state, action) => {
state[action.payload.remote].selectedBucket = action.payload.bucket;
},
},
extraReducers: (builder) => {
builder.addCase(getUserBuckets.fulfilled),
(state, action) => {
const { buckets, originOrDestination } = action.payload;
if (originOrDestination === 'origin') state.origin.buckets = buckets;
else if (originOrDestination === 'destination')
state.destination.buckets = buckets;
};
},
});
export default slice.reducer;
export const {
migrationStatusChange,
updateRemoteCredentials,
updateOriginAccessId,
updateOriginSecretKey,
updateDestinationSecretKey,
updateDestinationAccessId,
updateAccountId,
updateOriginBuckets,
updateSelectedBucket,
} = slice.actions;