EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
cwa-dual-test.tsx
Go to the documentation of this file.
1'use client';
2
3import { useState } from 'react';
4import { cwaApi } from '@/lib/cwa-gnap-api';
5import { cwaPosApi, setCWAPosApiKey } from '@/lib/cwa-pos-api';
6
7export default function CWADualTestPage() {
8 const [apiKey, setApiKey] = useState('');
9 const [results, setResults] = useState<Record<string, any>>({});
10 const [loading, setLoading] = useState<Record<string, boolean>>({});
11 const [searchTerm, setSearchTerm] = useState('test');
12
13 const handleSetApiKey = () => {
14 // Set API key for both systems
15 cwaApi.setApiKey(apiKey);
16 setCWAPosApiKey(apiKey);
17 alert('API Key set for both Management and POS APIs');
18 };
19
20 const testEndpoint = async (name: string, apiCall: () => Promise<any>) => {
21 setLoading(prev => ({ ...prev, [name]: true }));
22 try {
23 const result = await apiCall();
24 setResults(prev => ({ ...prev, [name]: result }));
25 } catch (error) {
26 setResults(prev => ({
27 ...prev,
28 [name]: { error: error instanceof Error ? error.message : 'Unknown error' }
29 }));
30 }
31 setLoading(prev => ({ ...prev, [name]: false }));
32 };
33
34 return (
35 <div className="min-h-screen bg-bg p-8">
36 <div className="max-w-6xl mx-auto">
37 <h1 className="text-4xl font-bold text-text mb-8">
38 CWA Dual API Test Dashboard
39 </h1>
40
41 {/* API Key Section */}
42 <div className="bg-surface p-6 rounded-lg shadow-md mb-8">
43 <h2 className="text-xl font-semibold mb-4">Authentication</h2>
44 <div className="flex gap-4">
45 <input
46 type="text"
47 value={apiKey}
48 onChange={(e) => setApiKey(e.target.value)}
49 placeholder="Enter FieldpineApiKey (e.g., BjjKmbw23IskPjxVGVMiqRhMcJBqtLYQRVHhYfnvMNp3IK)"
50 className="flex-1 p-2 border border-border rounded"
51 />
52 <button
53 onClick={handleSetApiKey}
54 className="px-4 py-2 bg-brand text-white rounded hover:bg-brand"
55 >
56 Set API Key
57 </button>
58 </div>
59 <p className="text-sm text-muted mt-2">
60 Use the FieldpineApiKey cookie value from your browser when authenticated to CWA
61 </p>
62 </div>
63
64 {/* API Systems Grid */}
65 <div className="grid grid-cols-1 lg:grid-cols-2 gap-8 mb-8">
66
67 {/* Management API Section */}
68 <div className="bg-surface p-6 rounded-lg shadow-lg">
69 <h2 className="text-2xl font-semibold mb-6 text-brand">
70 Management API (GNAP)
71 </h2>
72 <p className="text-sm text-muted mb-4">
73 Base: https://iig.cwanz.online/GNAP/j/BUCK?3=retailmax.elink.*
74 </p>
75
76 <div className="grid grid-cols-1 gap-4">
77 {/* Management API Endpoints */}
78 <button
79 onClick={() => testEndpoint('mgmt-locations', () => cwaApi.getLocations())}
80 disabled={loading['mgmt-locations']}
81 className="w-full p-3 bg-brand text-white rounded hover:bg-brand disabled:opacity-50"
82 >
83 {loading['mgmt-locations'] ? 'Loading...' : 'Get Locations'}
84 </button>
85
86 <button
87 onClick={() => testEndpoint('mgmt-stats', () => cwaApi.getStatsToday())}
88 disabled={loading['mgmt-stats']}
89 className="w-full p-3 bg-brand text-white rounded hover:bg-brand disabled:opacity-50"
90 >
91 {loading['mgmt-stats'] ? 'Loading...' : 'Get Stats Today'}
92 </button>
93
94 <button
95 onClick={() => testEndpoint('mgmt-server-status', () => cwaApi.getServerStatus())}
96 disabled={loading['mgmt-server-status']}
97 className="w-full p-3 bg-brand text-white rounded hover:bg-brand disabled:opacity-50"
98 >
99 {loading['mgmt-server-status'] ? 'Loading...' : 'Get Server Status'}
100 </button>
101
102 <button
103 onClick={() => testEndpoint('mgmt-config', () => cwaApi.getRetailConfig())}
104 disabled={loading['mgmt-config']}
105 className="w-full p-3 bg-brand text-white rounded hover:bg-brand disabled:opacity-50"
106 >
107 {loading['mgmt-config'] ? 'Loading...' : 'Get Retail Config'}
108 </button>
109 </div>
110 </div>
111
112 {/* POS API Section */}
113 <div className="bg-surface p-6 rounded-lg shadow-lg">
114 <h2 className="text-2xl font-semibold mb-6 text-green-600">
115 POS API (OpenAPI)
116 </h2>
117 <p className="text-sm text-muted mb-4">
118 Base: https://murwillumbah.cwanz.online/openapi/*
119 </p>
120
121 <div className="grid grid-cols-1 gap-4">
122 {/* Product Search Input */}
123 <div className="mb-4">
124 <label className="block text-sm font-medium mb-2">Product Search:</label>
125 <input
126 type="text"
127 value={searchTerm}
128 onChange={(e) => setSearchTerm(e.target.value)}
129 placeholder="Enter search term..."
130 className="w-full p-2 border border-border rounded"
131 />
132 </div>
133
134 {/* POS API Endpoints */}
135 <button
136 onClick={() => testEndpoint('pos-config', () => cwaPosApi.getRetailConfig())}
137 disabled={loading['pos-config']}
138 className="w-full p-3 bg-success text-white rounded hover:bg-green-600 disabled:opacity-50"
139 >
140 {loading['pos-config'] ? 'Loading...' : 'Get POS Config'}
141 </button>
142
143 <button
144 onClick={() => testEndpoint('pos-products', () => cwaPosApi.searchProducts(searchTerm))}
145 disabled={loading['pos-products']}
146 className="w-full p-3 bg-success text-white rounded hover:bg-green-600 disabled:opacity-50"
147 >
148 {loading['pos-products'] ? 'Loading...' : `Search Products: "${searchTerm}"`}
149 </button>
150
151 <button
152 onClick={() => testEndpoint('pos-payments', () => cwaPosApi.getPaymentTypes())}
153 disabled={loading['pos-payments']}
154 className="w-full p-3 bg-success text-white rounded hover:bg-green-600 disabled:opacity-50"
155 >
156 {loading['pos-payments'] ? 'Loading...' : 'Get Payment Types'}
157 </button>
158
159 <button
160 onClick={() => testEndpoint('pos-sale-template', () => cwaPosApi.getSaleListTemplate())}
161 disabled={loading['pos-sale-template']}
162 className="w-full p-3 bg-success text-white rounded hover:bg-green-600 disabled:opacity-50"
163 >
164 {loading['pos-sale-template'] ? 'Loading...' : 'Get Sale Template'}
165 </button>
166 </div>
167 </div>
168 </div>
169
170 {/* Results Section */}
171 <div className="bg-surface p-6 rounded-lg shadow-lg">
172 <h2 className="text-xl font-semibold mb-4">API Responses</h2>
173
174 {Object.keys(results).length === 0 ? (
175 <p className="text-muted">No API calls made yet. Click a button above to test an endpoint.</p>
176 ) : (
177 <div className="space-y-6">
178 {Object.entries(results).map(([name, result]) => (
179 <div key={name} className="border border-border rounded p-4">
180 <h3 className="font-semibold text-lg mb-2 capitalize flex items-center gap-2">
181 {name.startsWith('mgmt-') && <span className="text-brand">📊</span>}
182 {name.startsWith('pos-') && <span className="text-green-500">🛒</span>}
183 {name.replace(/^(mgmt|pos)-/, '').replace(/-/g, ' ')}
184 </h3>
185 <pre className="bg-surface-2 p-3 rounded text-sm overflow-x-auto max-h-64 overflow-y-auto">
186 {JSON.stringify(result, null, 2)}
187 </pre>
188 </div>
189 ))}
190 </div>
191 )}
192 </div>
193
194 {/* Information Section */}
195 <div className="mt-8 grid grid-cols-1 md:grid-cols-2 gap-8">
196
197 {/* Management API Info */}
198 <div className="bg-info/10 p-6 rounded-lg">
199 <h3 className="text-xl font-semibold mb-4 text-info">Management API</h3>
200 <div className="space-y-2 text-sm">
201 <p><strong>Purpose:</strong> Store management, reporting, admin functions</p>
202 <p><strong>Base URL:</strong> https://iig.cwanz.online/GNAP/j</p>
203 <p><strong>Pattern:</strong> /BUCK?3=retailmax.elink.*</p>
204 <p><strong>Auth:</strong> FieldpineApiKey cookie</p>
205 </div>
206
207 <div className="mt-4">
208 <h4 className="font-semibold mb-2">Available Endpoints:</h4>
209 <ul className="text-sm text-text space-y-1">
210 <li>• retailmax.elink.locations</li>
211 <li>• retailmax.elink.stats.today</li>
212 <li>• retailmax.elink.sale.totals</li>
213 <li>• retailmax.elink.userinterface</li>
214 <li>• gds.server.status</li>
215 <li>• retailmax.elink.config.setting</li>
216 </ul>
217 </div>
218 </div>
219
220 {/* POS API Info */}
221 <div className="bg-green-50 p-6 rounded-lg">
222 <h3 className="text-xl font-semibold mb-4 text-green-700">POS API</h3>
223 <div className="space-y-2 text-sm">
224 <p><strong>Purpose:</strong> Point of sale operations, product search, transactions</p>
225 <p><strong>Base URL:</strong> https://murwillumbah.cwanz.online/openapi</p>
226 <p><strong>Pattern:</strong> Direct endpoints + BUCK for products</p>
227 <p><strong>Auth:</strong> FieldpineApiKey cookie</p>
228 </div>
229
230 <div className="mt-4">
231 <h4 className="font-semibold mb-2">Available Endpoints:</h4>
232 <ul className="text-sm text-text space-y-1">
233 <li>• /retailconfig</li>
234 <li>• BUCK?3=retailmax.elink.products.list</li>
235 <li>• /PaymentTypes</li>
236 <li>• /salelist1.htm</li>
237 <li>• /saleheader1.htm</li>
238 <li>• /paymentsingle.htm</li>
239 </ul>
240 </div>
241 </div>
242 </div>
243 </div>
244 </div>
245 );
246}