forked from Adamantine-guild/guildpass-integrations
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscenario-selector.tsx
More file actions
151 lines (134 loc) · 4.25 KB
/
Copy pathscenario-selector.tsx
File metadata and controls
151 lines (134 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* Scenario Selector Component
*
* Developer tool for testing different mock scenarios including
* concurrent policy editing
*/
"use client";
import { useState, useId } from "react";
import { Button } from "@/components/ui/button";
import { Select } from "@/components/ui/select";
import { applyMockScenario, resetMockData } from "@/lib/api";
import { config } from "@/lib/config";
type MockScenario =
| 'active-member'
| 'expired-member'
| 'denied-resource'
| 'admin-session-expired'
| 'no-roles'
| 'multiple-communities'
| 'concurrent-policy-edit'
| 'customized-profile';
const SCENARIOS: Record<MockScenario, string> = {
'active-member': 'Active Standard Member',
'expired-member': 'Expired Member',
'denied-resource': 'Free Tier (Denied Access)',
'admin-session-expired': 'Admin with Expired Session',
'no-roles': 'Member with No Roles',
'multiple-communities': 'Multi-Community Member',
'concurrent-policy-edit': 'Concurrent Policy Edit (Admin)',
'customized-profile': 'Customized Profile (Avatar, Bio, Links)',
};
export function ScenarioSelector() {
const [selectedScenario, setSelectedScenario] = useState<MockScenario>('active-member');
const [isApplying, setIsApplying] = useState(false);
const [message, setMessage] = useState("");
const selectId = useId();
// Only show in mock mode
if (config.apiMode !== 'mock') {
return null;
}
const handleApply = async () => {
setIsApplying(true);
setMessage("");
try {
// Use a demo address
const demoAddress = '0x1234567890123456789012345678901234567890';
await applyMockScenario(selectedScenario, demoAddress);
setMessage(`✓ Applied scenario: ${SCENARIOS[selectedScenario]}`);
// Reload the page to reflect changes
setTimeout(() => {
window.location.reload();
}, 1000);
} catch (error) {
setMessage(`✗ Failed to apply scenario: ${error}`);
} finally {
setIsApplying(false);
}
};
const handleReset = async () => {
setIsApplying(true);
setMessage("");
try {
await resetMockData();
setMessage("✓ Mock data reset to defaults");
setTimeout(() => {
window.location.reload();
}, 1000);
} catch (error) {
setMessage(`✗ Failed to reset: ${error}`);
} finally {
setIsApplying(false);
}
};
return (
<div
role="region"
aria-label="Mock Scenario Tester"
className="rounded-lg border border-blue-500/50 bg-blue-500/10 p-4 space-y-3"
>
<div className="flex items-center gap-2">
<label htmlFor={selectId} className="text-sm font-medium cursor-pointer">
🧪 Mock Scenario Tester
</label>
</div>
<div className="space-y-2">
<Select
id={selectId}
aria-label="Select mock scenario"
value={selectedScenario}
onChange={(e) => setSelectedScenario(e.target.value as MockScenario)}
disabled={isApplying}
aria-disabled={isApplying}
className="w-full"
>
{Object.entries(SCENARIOS).map(([key, label]) => (
<option key={key} value={key}>
{label}
</option>
))}
</Select>
<div className="flex gap-2">
<Button
type="button"
size="sm"
onClick={handleApply}
disabled={isApplying}
aria-disabled={isApplying}
aria-busy={isApplying}
className="flex-1"
>
{isApplying ? "Applying..." : "Apply Scenario"}
</Button>
<Button
type="button"
size="sm"
variant="outline"
onClick={handleReset}
disabled={isApplying}
aria-disabled={isApplying}
>
Reset
</Button>
</div>
{message && (
<p role="status" aria-live="polite" className="text-xs text-muted-foreground">{message}</p>
)}
</div>
<div className="text-xs text-muted-foreground">
<strong>Concurrent Policy Edit:</strong> Sets the "alpha" policy as recently modified
by another admin, triggering a conflict when you try to save.
</div>
</div>
);
}