summaryrefslogtreecommitdiff
path: root/js/Pepe.tsx
blob: c829058178f644e9de4fecf6f0a4509e10394650 (plain)
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
"use client";

import type React from "react";

import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card";
import { Alert, AlertDescription } from "@/components/ui/alert";
import {
  Loader2,
  Server,
  MapPin,
  CheckCircle,
  AlertCircle,
  Key,
} from "lucide-react";

// Mock data for locations
const mockLocations = [
  {
    id: "nyc",
    city: "New York",
    country: "United States",
    flag: "πŸ‡ΊπŸ‡Έ",
    region: "North America",
  },
  {
    id: "lon",
    city: "London",
    country: "United Kingdom",
    flag: "πŸ‡¬πŸ‡§",
    region: "Europe",
  },
  {
    id: "fra",
    city: "Frankfurt",
    country: "Germany",
    flag: "πŸ‡©πŸ‡ͺ",
    region: "Europe",
  },
  {
    id: "sgp",
    city: "Singapore",
    country: "Singapore",
    flag: "πŸ‡ΈπŸ‡¬",
    region: "Asia Pacific",
  },
  {
    id: "tok",
    city: "Tokyo",
    country: "Japan",
    flag: "πŸ‡―πŸ‡΅",
    region: "Asia Pacific",
  },
  {
    id: "syd",
    city: "Sydney",
    country: "Australia",
    flag: "πŸ‡¦πŸ‡Ί",
    region: "Asia Pacific",
  },
  {
    id: "tor",
    city: "Toronto",
    country: "Canada",
    flag: "πŸ‡¨πŸ‡¦",
    region: "North America",
  },
  {
    id: "ams",
    city: "Amsterdam",
    country: "Netherlands",
    flag: "πŸ‡³πŸ‡±",
    region: "Europe",
  },
];

type Step = "api-key" | "location-select" | "creating" | "success" | "error";

interface Location {
  id: string;
  city: string;
  country: string;
  flag: string;
  region: string;
}

export default function VPSProvider() {
  const [step, setStep] = useState<Step>("api-key");
  const [apiKey, setApiKey] = useState("");
  const [selectedLocation, setSelectedLocation] = useState<Location | null>(
    null,
  );
  const [error, setError] = useState("");
  const [isValidating, setIsValidating] = useState(false);
  const [isCreating, setIsCreating] = useState(false);

  // Mock API key validation
  const validateApiKey = async (key: string) => {
    setIsValidating(true);
    setError("");

    // Simulate API call
    await new Promise((resolve) => setTimeout(resolve, 1500));

    // Mock validation - accept keys that are at least 20 characters
    if (key.length >= 20) {
      setStep("location-select");
    } else {
      setError("Invalid API key. Please check your credentials and try again.");
    }

    setIsValidating(false);
  };

  // Mock VPS creation
  const createVPS = async (location: Location) => {
    setIsCreating(true);
    setError("");
    setStep("creating");

    // Simulate VPS creation
    await new Promise((resolve) => setTimeout(resolve, 3000));

    // Mock success/failure (90% success rate)
    if (Math.random() > 0.1) {
      setStep("success");
    } else {
      setError("Failed to create VPS. Please try again or contact support.");
      setStep("error");
    }

    setIsCreating(false);
  };

  const handleApiKeySubmit = (e: React.FormEvent) => {
    e.preventDefault();
    if (apiKey.trim()) {
      validateApiKey(apiKey.trim());
    }
  };

  const handleLocationSelect = (location: Location) => {
    setSelectedLocation(location);
    createVPS(location);
  };

  const handleRetry = () => {
    setError("");
    setStep("location-select");
    setSelectedLocation(null);
  };

  const handleNext = () => {
    // This is where the user's flow continues
    console.log("Proceeding to next step...");
  };

  const renderApiKeyStep = () => (
    <Card className="w-full max-w-md mx-auto">
      <CardHeader className="text-center">
        <div className="mx-auto w-12 h-12 bg-blue-100 rounded-full flex items-center justify-center mb-4">
          <Key className="w-6 h-4 text-blue-600" />
        </div>
        <CardTitle>Connect Your Account</CardTitle>
        <CardDescription>
          Enter your API key to get started with VPS deployment
        </CardDescription>
      </CardHeader>
      <CardContent>
        <form onSubmit={handleApiKeySubmit} className="space-y-4">
          <div className="space-y-2">
            <Label htmlFor="apiKey">API Key</Label>
            <Input
              id="apiKey"
              type="password"
              placeholder="Enter your API key..."
              value={apiKey}
              onChange={(e) => setApiKey(e.target.value)}
              disabled={isValidating}
            />
          </div>

          {error && (
            <Alert variant="destructive">
              <AlertCircle className="h-4 w-4" />
              <AlertDescription>{error}</AlertDescription>
            </Alert>
          )}

          <Button
            type="submit"
            className="w-full"
            disabled={!apiKey.trim() || isValidating}
          >
            {isValidating ? (
              <>
                <Loader2 className="mr-2 h-4 w-4 animate-spin" />
                Validating...
              </>
            ) : (
              "Validate API Key"
            )}
          </Button>
        </form>
      </CardContent>
    </Card>
  );

  const renderLocationSelect = () => (
    <Card className="w-full max-w-4xl mx-auto">
      <CardHeader className="text-center">
        <div className="mx-auto w-12 h-12 bg-green-100 rounded-full flex items-center justify-center mb-4">
          <MapPin className="w-6 h-6 text-green-600" />
        </div>
        <CardTitle>Choose Server Location</CardTitle>
        <CardDescription>
          Select the location where you want to deploy your VPS
        </CardDescription>
      </CardHeader>
      <CardContent>
        <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
          {mockLocations.map((location) => (
            <Card
              key={location.id}
              className="cursor-pointer hover:shadow-md transition-shadow border-2 hover:border-blue-200"
              onClick={() => handleLocationSelect(location)}
            >
              <CardContent className="p-4">
                <div className="flex items-center space-x-3">
                  <span className="text-2xl">{location.flag}</span>
                  <div className="flex-1">
                    <h3 className="font-semibold">{location.city}</h3>
                    <p className="text-sm text-muted-foreground">
                      {location.country}
                    </p>
                    <p className="text-xs text-muted-foreground">
                      {location.region}
                    </p>
                  </div>
                </div>
              </CardContent>
            </Card>
          ))}
        </div>
      </CardContent>
    </Card>
  );

  const renderCreating = () => (
    <Card className="w-full max-w-md mx-auto">
      <CardHeader className="text-center">
        <div className="mx-auto w-12 h-12 bg-blue-100 rounded-full flex items-center justify-center mb-4">
          <Loader2 className="w-6 h-6 text-blue-600 animate-spin" />
        </div>
        <CardTitle>Creating Your VPS</CardTitle>
        <CardDescription>
          Setting up your server in {selectedLocation?.city},{" "}
          {selectedLocation?.country}
        </CardDescription>
      </CardHeader>
      <CardContent className="text-center">
        <div className="flex items-center justify-center space-x-2 mb-4">
          <span className="text-2xl">{selectedLocation?.flag}</span>
          <span className="font-medium">{selectedLocation?.city}</span>
        </div>
        <p className="text-sm text-muted-foreground">
          This may take a few minutes. Please don't close this window.
        </p>
      </CardContent>
    </Card>
  );

  const renderSuccess = () => (
    <Card className="w-full max-w-md mx-auto">
      <CardHeader className="text-center">
        <div className="mx-auto w-12 h-12 bg-green-100 rounded-full flex items-center justify-center mb-4">
          <CheckCircle className="w-6 h-6 text-green-600" />
        </div>
        <CardTitle>VPS Created Successfully!</CardTitle>
        <CardDescription>
          Your server is ready in {selectedLocation?.city},{" "}
          {selectedLocation?.country}
        </CardDescription>
      </CardHeader>
      <CardContent className="text-center space-y-4">
        <div className="flex items-center justify-center space-x-2 mb-4">
          <span className="text-2xl">{selectedLocation?.flag}</span>
          <span className="font-medium">{selectedLocation?.city}</span>
        </div>

        <Alert>
          <Server className="h-4 w-4" />
          <AlertDescription>
            Your VPS is now online and ready to use!
          </AlertDescription>
        </Alert>

        <Button onClick={handleNext} className="w-full">
          Next
        </Button>
      </CardContent>
    </Card>
  );

  const renderError = () => (
    <Card className="w-full max-w-md mx-auto">
      <CardHeader className="text-center">
        <div className="mx-auto w-12 h-12 bg-red-100 rounded-full flex items-center justify-center mb-4">
          <AlertCircle className="w-6 h-6 text-red-600" />
        </div>
        <CardTitle>Creation Failed</CardTitle>
        <CardDescription>
          We couldn't create your VPS at this time
        </CardDescription>
      </CardHeader>
      <CardContent className="text-center space-y-4">
        {error && (
          <Alert variant="destructive">
            <AlertCircle className="h-4 w-4" />
            <AlertDescription>{error}</AlertDescription>
          </Alert>
        )}

        <div className="flex space-x-2">
          <Button variant="outline" onClick={handleRetry} className="flex-1">
            Try Again
          </Button>
          <Button
            variant="outline"
            onClick={() => setStep("api-key")}
            className="flex-1"
          >
            Start Over
          </Button>
        </div>
      </CardContent>
    </Card>
  );

  return (
    <div className="min-h-screen bg-gray-50 py-12 px-4">
      <div className="max-w-6xl mx-auto">
        <div className="text-center mb-8">
          <h1 className="text-3xl font-bold text-gray-900 mb-2">
            Cloud VPS Deployment
          </h1>
          <p className="text-gray-600">
            Deploy your virtual private server in minutes
          </p>
        </div>

        {step === "api-key" && renderApiKeyStep()}
        {step === "location-select" && renderLocationSelect()}
        {step === "creating" && renderCreating()}
        {step === "success" && renderSuccess()}
        {step === "error" && renderError()}
      </div>
    </div>
  );
}