1 | import React from 'react'
|
---|
2 |
|
---|
3 | import { useSelector, useDispatch } from 'react-redux'
|
---|
4 |
|
---|
5 | import { HiOutlineArrowNarrowRight } from 'react-icons/hi'
|
---|
6 |
|
---|
7 | import axios from 'axios'
|
---|
8 |
|
---|
9 | import { setBlackjack, setStyle } from '../redux/reducers/styleSlice'
|
---|
10 | import { setBlackjackGame } from '../redux/reducers/playerSlice'
|
---|
11 |
|
---|
12 | const Alert = ({ onTop = false }) => {
|
---|
13 | const playerState = useSelector(state => state.player)
|
---|
14 | const styleState = useSelector(state => state.style)
|
---|
15 |
|
---|
16 | const dispatch = useDispatch()
|
---|
17 |
|
---|
18 | const display = styleState?.style?.alert?.show ? 'flex' : 'none'
|
---|
19 |
|
---|
20 | function clicked() {
|
---|
21 | dispatch(setStyle({
|
---|
22 | ...styleState.style,
|
---|
23 | alert: {
|
---|
24 | ...styleState.style.alert,
|
---|
25 | show: false
|
---|
26 | }
|
---|
27 | }))
|
---|
28 |
|
---|
29 | if (styleState.style.alert.button.action === 'play_again') {
|
---|
30 | axios.get(`/api/blackjack?action=play_again&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => {
|
---|
31 | if (res.data?.success && res.data?.game) {
|
---|
32 | dispatch(setBlackjackGame({
|
---|
33 | ...playerState.blackjackGame,
|
---|
34 | status: res.data.game?.status,
|
---|
35 | playerCards: res.data.game?.playerCards,
|
---|
36 | dealerCards: res.data.game?.dealerCards,
|
---|
37 | sideBetName: res.data.game?.sideBetName,
|
---|
38 | }))
|
---|
39 |
|
---|
40 | dispatch(setBlackjack({
|
---|
41 | ...styleState.blackjack,
|
---|
42 | inputControls: {
|
---|
43 | ...styleState.blackjack.inputControls,
|
---|
44 | initialBet: {
|
---|
45 | ...styleState.blackjack.inputControls.initialBet,
|
---|
46 | chosenCredits: parseInt(playerState.player.credits/2),
|
---|
47 | },
|
---|
48 | sideBet: {
|
---|
49 | ...styleState.blackjack.inputControls.sideBet,
|
---|
50 | chosenCredits: parseInt(0),
|
---|
51 | }
|
---|
52 | },
|
---|
53 | displays: {
|
---|
54 | ...styleState.blackjack.displays,
|
---|
55 | initialBet: true,
|
---|
56 | hitStand: false,
|
---|
57 | }
|
---|
58 | }))
|
---|
59 | }
|
---|
60 | });
|
---|
61 | }
|
---|
62 | else if (styleState.style.alert.button.action === 'continue_from_side_bet') {
|
---|
63 | dispatch(setBlackjack({
|
---|
64 | ...styleState.blackjack,
|
---|
65 | inputControls: {
|
---|
66 | ...styleState.blackjack.inputControls,
|
---|
67 | sideBet: {
|
---|
68 | ...styleState.blackjack.inputControls.sideBet,
|
---|
69 | chosenCredits: parseInt(0),
|
---|
70 | }
|
---|
71 | },
|
---|
72 | }))
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | return (
|
---|
77 | <div className="alert" style={{display: display, top: `${onTop ? '35vh' : '50vh'}`}}>
|
---|
78 | <h1>{styleState.style.alert.title}</h1>
|
---|
79 | <h3>{styleState.style.alert.subtitle}</h3>
|
---|
80 | <button className='primaryButton' onClick={() => clicked()}>{styleState.style.alert.button.text} <HiOutlineArrowNarrowRight style={{marginTop: '3px', marginBottom: '-3px'}} /></button>
|
---|
81 | </div>
|
---|
82 | )
|
---|
83 | }
|
---|
84 |
|
---|
85 | export default Alert |
---|