code to avoid duplicate account entry in otherAccounts

This commit is contained in:
Nouman Tahir 2023-06-26 15:28:31 +05:00
parent 886c754907
commit f3cebcbff1

View File

@ -72,7 +72,11 @@ export default function (state = initialState, action) {
otherAccounts: state.otherAccounts.some(
({ username }) => username === get(action.payload, 'username'),
)
? [...state.otherAccounts]
//replace account data if it already exists
? [...state.otherAccounts.filter(
(item) => item.username !== action.payload.username), action.payload]
//add new account entry if it does not already exist
: [...state.otherAccounts, action.payload],
isFetching: false,
hasError: false,