@rpg-engine/long-bow 0.8.198 → 0.8.200

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,258 @@
1
+ import React, { useState } from 'react';
2
+ import { FaCheckCircle, FaExclamationCircle, FaTicketAlt } from 'react-icons/fa';
3
+ import styled, { keyframes } from 'styled-components';
4
+ import { uiColors } from '../../../constants/uiColors';
5
+ import { CTAButton } from '../../shared/CTAButton/CTAButton';
6
+
7
+ type RedeemStatus = 'idle' | 'loading' | 'success' | 'error';
8
+
9
+ export interface IStoreRedeemSectionProps {
10
+ onRedeem: (code: string) => Promise<{ success: boolean; dcAmount?: number; error?: string }>;
11
+ onInputFocus?: () => void;
12
+ onInputBlur?: () => void;
13
+ }
14
+
15
+ export const StoreRedeemSection: React.FC<IStoreRedeemSectionProps> = ({
16
+ onRedeem,
17
+ onInputFocus,
18
+ onInputBlur,
19
+ }) => {
20
+ const [code, setCode] = useState('');
21
+ const [status, setStatus] = useState<RedeemStatus>('idle');
22
+ const [dcAmount, setDcAmount] = useState<number | undefined>();
23
+ const [errorMessage, setErrorMessage] = useState('');
24
+
25
+ const canSubmit = code.trim().length > 0 && status !== 'loading';
26
+
27
+ const handleSubmit = async (): Promise<void> => {
28
+ if (!canSubmit) return;
29
+
30
+ const normalizedCode = code.trim().toUpperCase();
31
+ setStatus('loading');
32
+ setErrorMessage('');
33
+
34
+ try {
35
+ const result = await onRedeem(normalizedCode);
36
+ if (result.success) {
37
+ setStatus('success');
38
+ setDcAmount(result.dcAmount);
39
+ } else {
40
+ setStatus('error');
41
+ setErrorMessage(result.error ?? 'Redemption failed. Please try again.');
42
+ }
43
+ } catch {
44
+ setStatus('error');
45
+ setErrorMessage('Something went wrong. Please try again.');
46
+ }
47
+ };
48
+
49
+ const handleReset = (): void => {
50
+ setCode('');
51
+ setStatus('idle');
52
+ setDcAmount(undefined);
53
+ setErrorMessage('');
54
+ };
55
+
56
+ const handleKeyDown = (e: React.KeyboardEvent): void => {
57
+ if (e.key === 'Enter') {
58
+ void handleSubmit();
59
+ }
60
+ };
61
+
62
+ if (status === 'success') {
63
+ return (
64
+ <Container>
65
+ <ResultContainer>
66
+ <SuccessIcon>
67
+ <FaCheckCircle size={32} />
68
+ </SuccessIcon>
69
+ <SuccessTitle>Code Redeemed!</SuccessTitle>
70
+ {dcAmount != null && (
71
+ <DCAmountDisplay>+{dcAmount.toLocaleString()} DC</DCAmountDisplay>
72
+ )}
73
+ <SuccessHint>Your wallet balance has been updated.</SuccessHint>
74
+ <ButtonWrapper>
75
+ <CTAButton
76
+ icon={<FaTicketAlt />}
77
+ label="Redeem Another"
78
+ onClick={handleReset}
79
+ />
80
+ </ButtonWrapper>
81
+ </ResultContainer>
82
+ </Container>
83
+ );
84
+ }
85
+
86
+ if (status === 'error') {
87
+ return (
88
+ <Container>
89
+ <ResultContainer>
90
+ <ErrorIcon>
91
+ <FaExclamationCircle size={32} />
92
+ </ErrorIcon>
93
+ <ErrorTitle>{errorMessage}</ErrorTitle>
94
+ <ButtonWrapper>
95
+ <CTAButton
96
+ icon={<FaTicketAlt />}
97
+ label="Try Again"
98
+ onClick={handleReset}
99
+ />
100
+ </ButtonWrapper>
101
+ </ResultContainer>
102
+ </Container>
103
+ );
104
+ }
105
+
106
+ return (
107
+ <Container>
108
+ <Title>Redeem a Voucher Code</Title>
109
+ <Description>
110
+ Enter your voucher code below to receive Definya Coins.
111
+ </Description>
112
+ <InputRow>
113
+ <CodeInput
114
+ type="text"
115
+ value={code}
116
+ onChange={(e) => setCode(e.target.value)}
117
+ onFocus={onInputFocus}
118
+ onBlur={onInputBlur}
119
+ onKeyDown={handleKeyDown}
120
+ placeholder="Enter code..."
121
+ disabled={status === 'loading'}
122
+ autoComplete="off"
123
+ spellCheck={false}
124
+ />
125
+ </InputRow>
126
+ <ButtonWrapper>
127
+ <CTAButton
128
+ icon={<FaTicketAlt />}
129
+ label={status === 'loading' ? 'Redeeming...' : 'Redeem Code'}
130
+ onClick={() => { void handleSubmit(); }}
131
+ disabled={!canSubmit}
132
+ fullWidth
133
+ />
134
+ </ButtonWrapper>
135
+ </Container>
136
+ );
137
+ };
138
+
139
+ const Container = styled.div`
140
+ display: flex;
141
+ flex-direction: column;
142
+ align-items: center;
143
+ justify-content: center;
144
+ padding: 2rem 1.5rem;
145
+ max-width: 420px;
146
+ margin: 0 auto;
147
+ gap: 1rem;
148
+ `;
149
+
150
+ const Title = styled.h3`
151
+ font-family: 'Press Start 2P', cursive;
152
+ font-size: 0.85rem;
153
+ color: ${uiColors.white};
154
+ margin: 0;
155
+ text-align: center;
156
+ `;
157
+
158
+ const Description = styled.p`
159
+ font-family: 'Press Start 2P', cursive;
160
+ font-size: 0.55rem;
161
+ color: ${uiColors.lightGray};
162
+ margin: 0;
163
+ text-align: center;
164
+ line-height: 1.6;
165
+ `;
166
+
167
+ const InputRow = styled.div`
168
+ width: 100%;
169
+ `;
170
+
171
+ const CodeInput = styled.input`
172
+ width: 100%;
173
+ padding: 12px 14px;
174
+ font-family: 'Press Start 2P', cursive;
175
+ font-size: 0.75rem;
176
+ color: ${uiColors.white};
177
+ background: rgba(0, 0, 0, 0.4);
178
+ border: 2px solid #f59e0b;
179
+ border-radius: 4px;
180
+ text-transform: uppercase;
181
+ letter-spacing: 2px;
182
+ text-align: center;
183
+ box-sizing: border-box;
184
+ outline: none;
185
+
186
+ &::placeholder {
187
+ color: ${uiColors.lightGray};
188
+ text-transform: none;
189
+ letter-spacing: 0;
190
+ }
191
+
192
+ &:focus {
193
+ border-color: #fbbf24;
194
+ box-shadow: 0 0 8px rgba(251, 191, 36, 0.3);
195
+ }
196
+
197
+ &:disabled {
198
+ opacity: 0.5;
199
+ cursor: not-allowed;
200
+ }
201
+ `;
202
+
203
+ const ButtonWrapper = styled.div`
204
+ width: 100%;
205
+ margin-top: 0.5rem;
206
+ `;
207
+
208
+ const ResultContainer = styled.div`
209
+ display: flex;
210
+ flex-direction: column;
211
+ align-items: center;
212
+ gap: 1rem;
213
+ padding: 1rem 0;
214
+ `;
215
+
216
+ const glowPulse = keyframes`
217
+ 0%, 100% { opacity: 1; }
218
+ 50% { opacity: 0.7; }
219
+ `;
220
+
221
+ const SuccessIcon = styled.div`
222
+ color: ${uiColors.green};
223
+ animation: ${glowPulse} 1.5s ease-in-out infinite;
224
+ `;
225
+
226
+ const SuccessTitle = styled.h3`
227
+ font-family: 'Press Start 2P', cursive;
228
+ font-size: 0.85rem;
229
+ color: ${uiColors.green};
230
+ margin: 0;
231
+ `;
232
+
233
+ const DCAmountDisplay = styled.div`
234
+ font-family: 'Press Start 2P', cursive;
235
+ font-size: 1.2rem;
236
+ color: #fef08a;
237
+ text-shadow: 0 0 10px rgba(254, 240, 138, 0.5);
238
+ `;
239
+
240
+ const SuccessHint = styled.p`
241
+ font-family: 'Press Start 2P', cursive;
242
+ font-size: 0.5rem;
243
+ color: ${uiColors.lightGray};
244
+ margin: 0;
245
+ `;
246
+
247
+ const ErrorIcon = styled.div`
248
+ color: ${uiColors.red};
249
+ `;
250
+
251
+ const ErrorTitle = styled.p`
252
+ font-family: 'Press Start 2P', cursive;
253
+ font-size: 0.65rem;
254
+ color: ${uiColors.red};
255
+ margin: 0;
256
+ text-align: center;
257
+ line-height: 1.6;
258
+ `;
package/src/index.tsx CHANGED
@@ -85,6 +85,7 @@ export * from './components/Store/PaymentMethodModal';
85
85
  export * from './components/Store/PurchaseSuccess';
86
86
  export * from './components/Store/Store';
87
87
  export * from './components/Store/StoreBadges';
88
+ export * from './components/Store/sections/StoreRedeemSection';
88
89
  export * from './components/Store/TrustBar';
89
90
  export * from './components/Table/Table';
90
91
  export * from './components/TextArea';
@@ -564,3 +564,65 @@ export const INR: Story = {
564
564
  />
565
565
  ),
566
566
  };
567
+
568
+ export const WithRedeemTab: Story = {
569
+ render: () => (
570
+ <Store
571
+ items={duplicatedItems}
572
+ packs={mockPacks}
573
+ userAccountType={UserAccountTypes.Free}
574
+ onPurchase={(purchase: Partial<IPurchase>) => {
575
+ console.log('Purchase details:', purchase);
576
+ return Promise.resolve(true);
577
+ }}
578
+ onRedeem={async (code: string) => {
579
+ if (code === 'CHB-550-ABCDEF1234') {
580
+ return { success: true, dcAmount: 550 };
581
+ }
582
+
583
+ return { success: false, error: 'Invalid voucher code.' };
584
+ }}
585
+ customWalletContent={<DCWalletContent
586
+ dcBalance={1200}
587
+ historyData={{ transactions: [], totalPages: 1, currentPage: 1 }}
588
+ historyLoading={false}
589
+ onRequestHistory={() => {}}
590
+ transferLoading={false}
591
+ transferResult={null}
592
+ onSendTransfer={() => {}}
593
+ onClearTransferResult={() => {}}
594
+ onBuyDC={() => console.log('Buy DC')}
595
+ />}
596
+ customHistoryContent={<DCHistoryPanel
597
+ transactions={[]}
598
+ totalPages={1}
599
+ currentPage={1}
600
+ loading={false}
601
+ onRequestHistory={() => {}}
602
+ />}
603
+ onClose={() => console.log('Store closed')}
604
+ atlasJSON={itemsAtlasJSON}
605
+ atlasIMG={itemsAtlasIMG}
606
+ hidePremiumTab={true}
607
+ tabOrder={['items', 'packs', 'redeem']}
608
+ defaultActiveTab="redeem"
609
+ textInputItemKeys={['original-greater-life-potion-2', 'original-angelic-sword-1', 'character-name-change']}
610
+ onTabChange={(tab, count) => console.log('[tracking] tab_change', { tab, count })}
611
+ onCategoryChange={(category, count) => console.log('[tracking] category_change', { category, count })}
612
+ onItemView={(item, position) => console.log('[tracking] item_viewed', { key: item.key, position })}
613
+ onPackView={(pack, position) => console.log('[tracking] pack_viewed', { key: pack.key, position })}
614
+ onCartOpen={() => console.log('[tracking] cart_opened')}
615
+ onAddToCart={(item, qty) => console.log('[tracking] add_to_cart', { key: item.key, qty })}
616
+ onRemoveFromCart={(key) => console.log('[tracking] remove_from_cart', { key })}
617
+ onCheckoutStart={(items, total) => console.log('[tracking] checkout_start', { items, total })}
618
+ onPurchaseSuccess={(items, total) => console.log('[tracking] purchase_success', { items, total })}
619
+ onPurchaseError={(error) => console.log('[tracking] purchase_error', { error })}
620
+ itemBadges={{
621
+ 'original-greater-life-potion-0': { originalPrice: 15.00 },
622
+ 'character-name-change': { originalPrice: 15.00 },
623
+ 'skin-character-customization': { originalPrice: 20.00 },
624
+ 'starter-pack': { originalPrice: 9.99 }
625
+ }}
626
+ />
627
+ ),
628
+ };