Skip to content

Commit

Permalink
Merge pull request #310 from FuelRats/develop
Browse files Browse the repository at this point in the history
v2.12.8 - The one where we actually fixed decals for real this time I swear
  • Loading branch information
UncleClapton authored Feb 1, 2021
2 parents 124aeb4 + d97d306 commit ddf9e5b
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 3 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,22 @@ For detailed rules of this file, see [Changelog Rules](#changelog-rules)
### ⚙ Tasks
*


[#303]: https://github.com/fuelRats/fuelrats.com/pull/303
[Unreleased]: https://github.com/FuelRats/fuelrats.com/compare/v2.12.6...HEAD
[Unreleased]: https://github.com/FuelRats/fuelrats.com/compare/v2.12.8...HEAD





## [2.12.8][] - 2021-02-01

### 🐛 Fixed
* Fix multiple issues with redeeming decals - [#309][]


[#309]: https://github.com/fuelRats/fuelrats.com/pull/309
[2.12.8]: https://github.com/FuelRats/fuelrats.com/compare/v2.12.7...v2.12.8



Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fuelrats.com",
"version": "2.12.7",
"version": "2.12.8",
"description": "The primary website of The Fuel Rats!",
"main": "dist/server.js",
"license": "BSD-3-Clause",
Expand Down
2 changes: 1 addition & 1 deletion src/components/UserDecalPanel/UserDecalPanel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback, useState } from 'react'
import { useDispatch, useSelector } from 'react-redux'

import { redeemDecal } from '~/store/actions/decals'
import {
selectCurrentUserId,
selectDecalsByUserId,
Expand All @@ -24,7 +25,6 @@ function UserDetailsPanel () {
const handleRedeemDecal = useCallback(async () => {
setRedeeming(true)

// eslint-disable-next-line no-undef
await dispatch(redeemDecal(userId))

setRedeeming(false)
Expand Down
8 changes: 8 additions & 0 deletions src/store/actions/decals.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { defineRelationship } from '@fuelrats/web-util/redux-json-api'

import actionTypes from '../actionTypes'
import { createsRelationship, RESOURCE } from '../reducers/frAPIResources'
import { decrementsEligibleDecals } from '../reducers/users'
import { frApiRequest } from './services'


Expand All @@ -12,5 +16,9 @@ export const redeemDecal = (id) => {
url: `/users/${id}/decals`,
method: 'post',
},
createsRelationship(
defineRelationship({ type: 'users', id }, { decals: [RESOURCE] }),
),
decrementsEligibleDecals(id),
)
}
2 changes: 2 additions & 0 deletions src/store/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import images from './images'
import leaderboard from './leaderboard'
import pageViews from './pageViews'
import session from './session'
import users from './users'
import wordpress from './wordpress'


Expand All @@ -28,6 +29,7 @@ export default chainReducers(
leaderboard,
pageViews,
session,
users,
wordpress,
}),
],
Expand Down
40 changes: 40 additions & 0 deletions src/store/reducers/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { isError } from 'flux-standard-action'
import { produce } from 'immer'

import safeParseInt from '~/helpers/safeParseInt'

import actionTypes from '../actionTypes'
import initialState from '../initialState'

const metaKey = '__decals/decrement'

const usersReducer = produce((draftState, action) => {
if (isError(action)) {
return
}

switch (action.type) {
case actionTypes.decals.redeem:
if (action.meta[metaKey]) {
const user = draftState[action.meta[metaKey]]
if (user?.meta) {
user.meta.redeemable = Math.max(safeParseInt(user.meta.redeemable) - 1, 0)
}
}
break

default:
break
}
}, initialState.users)



export function decrementsEligibleDecals (id) {
return {
[metaKey]: id,
}
}


export default usersReducer

0 comments on commit ddf9e5b

Please sign in to comment.