EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
XeroCard.jsx
Go to the documentation of this file.
1import React, { useState } from 'react';
2
3function XeroCard({ config, status, loading, onConfigure, tenantId }) {
4 const [clientId, setClientId] = useState(config?.xero?.clientId || '');
5 const [clientSecret, setClientSecret] = useState(config?.xero?.clientSecret || '');
6 const [xeroTenantId, setXeroTenantId] = useState(config?.xero?.tenantId || '');
7 const [saving, setSaving] = useState(false);
8 const [saveStatus, setSaveStatus] = useState('');
9
10 const handleSave = async () => {
11 setSaving(true);
12 setSaveStatus('');
13 try {
14 const res = await fetch(`/api/xero/settings/${tenantId}`, {
15 method: 'POST',
16 headers: { 'Content-Type': 'application/json' },
17 body: JSON.stringify({
18 xero: { clientId, clientSecret, tenantId: xeroTenantId }
19 })
20 });
21 if (res.ok) {
22 setSaveStatus('Connected to Xero');
23 } else {
24 setSaveStatus('Failed to save Xero settings');
25 }
26 } catch (e) {
27 setSaveStatus('Error saving Xero settings');
28 }
29 setSaving(false);
30 };
31
32 return (
33 <div className="config-card">
34 <h3>Xero Integration</h3>
35 <p>Sync invoices and financial data with Xero accounting.</p>
36 <div className="form-row">
37 <label>
38 Client ID:
39 <input type="text" value={clientId} onChange={e => setClientId(e.target.value)} style={{ width: '240px' }} />
40 </label>
41 </div>
42 <div className="form-row">
43 <label>
44 Client Secret:
45 <input type="text" value={clientSecret} onChange={e => setClientSecret(e.target.value)} style={{ width: '240px' }} />
46 </label>
47 </div>
48 <div className="form-row">
49 <label>
50 Tenant ID:
51 <input type="text" value={xeroTenantId} onChange={e => setXeroTenantId(e.target.value)} style={{ width: '240px' }} />
52 </label>
53 </div>
54 <button onClick={handleSave} disabled={saving || loading} className="btn-primary">
55 {saving || loading ? 'Saving...' : 'Save Xero Settings'}
56 </button>
57 {(status || saveStatus) && (
58 <div className={`status-message ${(status || saveStatus).startsWith('Connected') ? 'success' : 'error'}`}>
59 {status || saveStatus}
60 </div>
61 )}
62 {config && (
63 <div className="current-config">
64 <b>Current config:</b> {JSON.stringify(config)}
65 </div>
66 )}
67 </div>
68 );
69}
70
71export default XeroCard;