Skip to content

Commit

Permalink
Combined enterprise gift article state to reduce duplication.
Browse files Browse the repository at this point in the history
  • Loading branch information
willhoward committed Jan 6, 2023
1 parent 873dd6f commit b84aa20
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions components/x-gift-article/src/GiftArticle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ const withGiftFormActions = withActions(
const { enabled, limit, hasCredits, firstTimeUser, requestAccess } =
await enterpriseApi.getEnterpriseArticleAllowance()

const enterpriseState = {
enterpriseLimit: limit,
enterpriseHasCredits: hasCredits,
enterpriseFirstTimeUser: firstTimeUser,
enterpriseRequestAccess: requestAccess
}

if (enabled) {
tracking.initEnterpriseSharing(
requestAccess
Expand All @@ -174,10 +181,7 @@ const withGiftFormActions = withActions(
return {
invalidResponseFromApi: true,
enterpriseEnabled: enabled,
enterpriseLimit: limit,
enterpriseHasCredits: hasCredits,
enterpriseFirstTimeUser: firstTimeUser,
enterpriseRequestAccess: requestAccess
...enterpriseState
}
} else {
const { giftCredits, monthlyAllowance, nextRenewalDate } = await api.getGiftArticleAllowance()
Expand All @@ -188,19 +192,13 @@ const withGiftFormActions = withActions(
...updaters.setAllowance(giftCredits, monthlyAllowance, nextRenewalDate),
shareType: enabled && hasCredits ? ShareType.enterprise : ShareType.gift,
enterpriseEnabled: enabled,
enterpriseLimit: limit,
enterpriseHasCredits: hasCredits,
enterpriseFirstTimeUser: firstTimeUser,
enterpriseRequestAccess: requestAccess
...enterpriseState
}
} else {
return {
invalidResponseFromApi: true,
enterpriseEnabled: enabled,
enterpriseLimit: limit,
enterpriseHasCredits: hasCredits,
enterpriseFirstTimeUser: firstTimeUser,
enterpriseRequestAccess: requestAccess
...enterpriseState
}
}
}
Expand Down

0 comments on commit b84aa20

Please sign in to comment.