Changeset View
Changeset View
Standalone View
Standalone View
lib/reducers/invite-links-reducer.js
// @flow | // @flow | ||||
import { fetchPrimaryInviteLinkActionTypes } from '../actions/link-actions.js'; | import { | ||||
createOrUpdatePublicLinkActionTypes, | |||||
fetchPrimaryInviteLinkActionTypes, | |||||
} 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, | ||||
): InviteLinksStore { | ): InviteLinksStore { | ||||
if (action.type === fetchPrimaryInviteLinkActionTypes.success) { | if (action.type === fetchPrimaryInviteLinkActionTypes.success) { | ||||
const links = {}; | const links = {}; | ||||
for (const link of action.payload.links) { | for (const link of action.payload.links) { | ||||
links[link.communityID] = { | links[link.communityID] = { | ||||
primaryLink: link, | primaryLink: link, | ||||
...state.links[link.communityID], | ...state.links[link.communityID], | ||||
}; | }; | ||||
} | } | ||||
return { | return { | ||||
links, | links, | ||||
}; | }; | ||||
} else if (action.type === createOrUpdatePublicLinkActionTypes.success) { | |||||
const communityID = action.payload.communityID; | |||||
return { | |||||
...state, | |||||
links: { | |||||
...state.links, | |||||
[communityID]: { | |||||
...state.links[communityID], | |||||
primaryLink: action.payload, | |||||
}, | |||||
}, | |||||
}; | |||||
} | } | ||||
return state; | return state; | ||||
} | } | ||||
export default reduceInviteLinks; | export default reduceInviteLinks; |