Changeset View
Changeset View
Standalone View
Standalone View
lib/reducers/invite-links-reducer.js
// @flow | // @flow | ||||
import { | import { | ||||
createOrUpdatePublicLinkActionTypes, | createOrUpdatePublicLinkActionTypes, | ||||
disableInviteLinkLinkActionTypes, | |||||
fetchPrimaryInviteLinkActionTypes, | fetchPrimaryInviteLinkActionTypes, | ||||
} from '../actions/link-actions.js'; | } from '../actions/link-actions.js'; | ||||
import type { InviteLinksStore } from '../types/link-types.js'; | import type { InviteLinksStore } from '../types/link-types.js'; | ||||
import type { BaseAction } from '../types/redux-types.js'; | import type { BaseAction } from '../types/redux-types.js'; | ||||
function reduceInviteLinks( | function reduceInviteLinks( | ||||
state: InviteLinksStore, | state: InviteLinksStore, | ||||
action: BaseAction, | action: BaseAction, | ||||
Show All 16 Lines | return { | ||||
links: { | links: { | ||||
...state.links, | ...state.links, | ||||
[communityID]: { | [communityID]: { | ||||
...state.links[communityID], | ...state.links[communityID], | ||||
primaryLink: action.payload, | primaryLink: action.payload, | ||||
}, | }, | ||||
}, | }, | ||||
}; | }; | ||||
} else if (action.type === disableInviteLinkLinkActionTypes.success) { | |||||
const communityID = action.payload.communityID; | |||||
const currentPrimaryLink = state.links[communityID]?.primaryLink; | |||||
const communityLinks = { | |||||
...state.links[communityID], | |||||
primaryLink: | |||||
currentPrimaryLink?.name === action.payload.name | |||||
kamil: I would move `currentPrimaryLink?.name === action.payload.name` condition to if upper, and… | |||||
? null | |||||
: currentPrimaryLink, | |||||
}; | |||||
return { | |||||
...state, | |||||
links: { | |||||
...state.links, | |||||
[communityID]: communityLinks, | |||||
}, | |||||
}; | |||||
} | } | ||||
return state; | return state; | ||||
} | } | ||||
export default reduceInviteLinks; | export default reduceInviteLinks; |
I would move currentPrimaryLink?.name === action.payload.name condition to if upper, and avoid modifying the state if it's falsy