GameProposal: Accept

This commit is contained in:
djmil 2023-11-15 21:19:49 +01:00
parent 60d6af94e1
commit cacc8c99d8
6 changed files with 28 additions and 5 deletions

View File

@ -90,4 +90,18 @@ public class GameProposalController {
return ResponseEntity
.ok(rejectedGameView);
}
@PutMapping("/{uuid}/accept")
public ResponseEntity<GameView> accept(
@AuthenticationPrincipal User issuer,
@PathVariable UUID uuid
) {
final GameView acceptedGameView = cordaClient.gameProposalAccept(
issuer.getHoldingIdentity(),
uuid
);
return ResponseEntity
.ok(acceptedGameView);
}
}

View File

@ -37,6 +37,12 @@ export default function useGamesApi(gamesReducer, config) {
onPushing: (isPushingGameProposalReject) => dispatchGames({ type: 'next', isPushingGameProposalReject }),
onSuccess: (rejectedGame) => dispatchGames({ type: 'next', gamesList: games.nextGameList(rejectedGame), proposal: gamesInitialState.proposal })
}),
pushGameProposalAccept: ({ uuid }) => ifNot(games.isPushingGameProposalAccept) &&
doPushing(`/api/gameproposal/${uuid}/accept`, 'PUT', null, {
onPushing: (isPushingGameProposalAccept) => dispatchGames({ type: 'next', isPushingGameProposalAccept }),
onSuccess: (acceptedGame) => dispatchGames({ type: 'next', gamesList: games.nextGameList(acceptedGame), proposal: gamesInitialState.proposal })
}),
}
}

View File

@ -96,7 +96,7 @@ function ActionPanel({ players, gamesApi }) {
/>
} />
<Route path='proposal' element={[
<Accept key={1} />,
<Accept key={1} onClick={(uuid) => gamesApi.pushGameProposalAccept({ uuid })}/>,
<Reject key={2} onClick={(uuid) => gamesApi.pushGameProposalReject({ uuid })} />,
<Cancel key={3} onClick={(uuid) => gamesApi.pushGameProposalCancel({ uuid })} />
]} />

View File

@ -1,4 +1,5 @@
import React, { useContext } from 'react';
import Wobler from '../../../components/Wobler';
import { GamesContext } from '../../../context/games';
export default function Accept({ onClick }) {
@ -9,8 +10,10 @@ export default function Accept({ onClick }) {
if (selectedGame?.status !== 'GAME_PROPOSAL_WAIT_FOR_OPPONENT')
return (
<button className={'Accept' + (isReady && ' ready')}>
Accept
<button className={'Accept' + (isReady && ' ready')}
onClick={() => isReady ? onClick(selectedGame.uuid) : alert('You have to select some GameProposal')}
>
<Wobler text="Accept" dance={games.isPushingGameProposalAccept} />
</button>
)
}

View File

@ -81,7 +81,6 @@ export async function doPushing(uri, method, data, { onSuccess, onPushing }) {
? await response.json()
: null;
console.log("rsponce", response, "content", content);
onSuccess(content);
}
// } catch (err) {

View File

@ -29,6 +29,7 @@ export const gamesInitialState = {
isPushingNewGame: false,
isPushingGameProposalCancel: false,
isPushingGameProposalReject: false,
isPushingGameProposalAccept: false,
findGame,
nextGameList,