-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-ui.sh
More file actions
executable file
·528 lines (465 loc) · 14 KB
/
setup-ui.sh
File metadata and controls
executable file
·528 lines (465 loc) · 14 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
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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
#!/bin/bash
# Create UI components directory and ensure it exists
mkdir -p src/components/ui
echo "Creating UI components in src/components/ui..."
# Create lib directory and ensure it exists
mkdir -p src/lib
echo "Creating utils.ts in src/lib..."
# Create utils.ts if it doesn't exist
cat > src/lib/utils.ts << 'EOL'
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
// Add formatDate function that was missing
export function formatDate(date: Date): string {
return new Intl.DateTimeFormat('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
}).format(date);
}
// Add formatCurrency function
export function formatCurrency(amount: number): string {
return new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
}).format(amount);
}
EOL
# Create button component
cat > src/components/ui/button.tsx << 'EOL'
"use client";
import * as React from "react";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";
const buttonVariants = cva(
"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:opacity-50 disabled:pointer-events-none",
{
variants: {
variant: {
default: "bg-blue-600 text-white hover:bg-blue-700",
destructive: "bg-red-600 text-white hover:bg-red-700",
outline: "border border-gray-300 bg-transparent hover:bg-gray-100",
secondary: "bg-gray-200 text-gray-900 hover:bg-gray-300",
ghost: "hover:bg-gray-100 hover:text-gray-900",
link: "text-blue-600 underline-offset-4 hover:underline",
},
size: {
default: "h-10 py-2 px-4",
sm: "h-9 px-3",
lg: "h-11 px-8",
icon: "h-10 w-10",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
);
export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
asChild?: boolean;
}
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, ...props }, ref) => {
return (
<button
className={cn(buttonVariants({ variant, size }), className)}
ref={ref}
{...props}
/>
);
}
);
Button.displayName = "Button";
export { Button, buttonVariants };
EOL
# Create card component
cat > src/components/ui/card.tsx << 'EOL'
"use client";
import * as React from "react";
import { cn } from "@/lib/utils";
const Card = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(
"rounded-lg border border-gray-200 bg-white shadow-sm",
className
)}
{...props}
/>
));
Card.displayName = "Card";
const CardHeader = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex flex-col space-y-1.5 p-6", className)}
{...props}
/>
));
CardHeader.displayName = "CardHeader";
const CardTitle = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLHeadingElement>
>(({ className, ...props }, ref) => (
<h3
ref={ref}
className={cn("text-xl font-semibold leading-none tracking-tight", className)}
{...props}
/>
));
CardTitle.displayName = "CardTitle";
const CardDescription = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement>
>(({ className, ...props }, ref) => (
<p
ref={ref}
className={cn("text-sm text-gray-500", className)}
{...props}
/>
));
CardDescription.displayName = "CardDescription";
const CardContent = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
));
CardContent.displayName = "CardContent";
const CardFooter = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex items-center p-6 pt-0", className)}
{...props}
/>
));
CardFooter.displayName = "CardFooter";
export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent };
EOL
# Create alert component
cat > src/components/ui/alert.tsx << 'EOL'
"use client";
import * as React from "react";
import { cn } from "@/lib/utils";
const Alert = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
role="alert"
className={cn(
"relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",
className
)}
{...props}
/>
));
Alert.displayName = "Alert";
const AlertTitle = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLHeadingElement>
>(({ className, ...props }, ref) => (
<h5
ref={ref}
className={cn("mb-1 font-medium leading-none tracking-tight", className)}
{...props}
/>
));
AlertTitle.displayName = "AlertTitle";
const AlertDescription = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("text-sm [&_p]:leading-relaxed", className)}
{...props}
/>
));
AlertDescription.displayName = "AlertDescription";
export { Alert, AlertTitle, AlertDescription };
EOL
# Create cloudinary-image component
cat > src/components/ui/cloudinary-image.tsx << 'EOL'
"use client";
import React from 'react';
import Image from 'next/image';
import { cn } from '@/lib/utils';
interface CloudinaryImageProps {
src?: string;
publicId?: string;
alt: string;
width?: number;
height?: number;
className?: string;
priority?: boolean;
sizes?: string;
quality?: number;
fill?: boolean;
style?: React.CSSProperties;
effect?: string;
transformations?: string;
}
interface CloudinaryBlurImageProps extends CloudinaryImageProps {
blurDataURL?: string;
}
const CloudinaryImage = ({
src,
publicId,
alt,
width = 800,
height = 600,
className,
priority = false,
sizes = '(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw',
quality = 80,
fill = false,
style,
effect,
transformations,
...props
}: CloudinaryImageProps & Omit<React.ComponentProps<typeof Image>, 'src' | 'alt' | 'width' | 'height'>) => {
const cloudName = process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME;
// Handle both src and publicId
let imageUrl = src;
if (publicId && cloudName) {
let transformation = 'q_auto,f_auto';
if (effect) transformation += `,e_${effect}`;
if (transformations) transformation += `,${transformations}`;
imageUrl = `https://res.cloudinary.com/${cloudName}/image/upload/${transformation}/${publicId}`;
} else if (src && !src.includes('res.cloudinary.com') && cloudName) {
imageUrl = `https://res.cloudinary.com/${cloudName}/image/upload/q_auto,f_auto/${src}`;
}
if (!imageUrl && !publicId) {
console.error('Either src or publicId must be provided to CloudinaryImage');
return null;
}
return (
<div className={cn('relative', className)} style={style}>
<Image
src={imageUrl || `https://res.cloudinary.com/${cloudName}/image/upload/q_auto,f_auto/${publicId}`}
alt={alt}
width={fill ? undefined : width}
height={fill ? undefined : height}
priority={priority}
sizes={sizes}
quality={quality}
fill={fill}
className={cn('object-cover', className)}
{...props}
/>
</div>
);
};
const CloudinaryBlurImage = ({
src,
publicId,
alt,
width = 800,
height = 600,
className,
priority = false,
sizes = '(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw',
quality = 80,
fill = false,
style,
blurDataURL,
effect,
transformations,
...props
}: CloudinaryBlurImageProps) => {
const cloudName = process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME;
// Handle both src and publicId
let imageUrl = src;
if (publicId && cloudName) {
let transformation = 'q_auto,f_auto';
if (effect) transformation += `,e_${effect}`;
if (transformations) transformation += `,${transformations}`;
imageUrl = `https://res.cloudinary.com/${cloudName}/image/upload/${transformation}/${publicId}`;
} else if (src && !src.includes('res.cloudinary.com') && cloudName) {
imageUrl = `https://res.cloudinary.com/${cloudName}/image/upload/q_auto,f_auto/${src}`;
}
if (!imageUrl && !publicId) {
console.error('Either src or publicId must be provided to CloudinaryBlurImage');
return null;
}
// Generate blur URL if not provided
const generatedBlurDataURL = blurDataURL ||
(cloudName && (publicId || src))
? `https://res.cloudinary.com/${cloudName}/image/upload/w_10,e_blur:1000/${publicId || src}`
: undefined;
return (
<div className={cn('relative', className)} style={style}>
<Image
src={imageUrl || `https://res.cloudinary.com/${cloudName}/image/upload/q_auto,f_auto/${publicId}`}
alt={alt}
width={fill ? undefined : width}
height={fill ? undefined : height}
priority={priority}
sizes={sizes}
quality={quality}
fill={fill}
className={cn('object-cover', className)}
placeholder="blur"
blurDataURL={generatedBlurDataURL}
{...props}
/>
</div>
);
};
export { CloudinaryImage, CloudinaryBlurImage };
EOL
# Create cloudinary-upload component
cat > src/components/ui/cloudinary-upload.tsx << 'EOL'
"use client";
import React, { useCallback } from 'react';
import { useDropzone } from 'react-dropzone';
import { cn } from '@/lib/utils';
interface CloudinaryUploadProps {
onUploadSuccess?: (result: any) => void;
onUploadError?: (error: any) => void;
buttonText?: string;
uploadPreset?: string;
className?: string;
buttonClassName?: string;
multiple?: boolean;
maxFiles?: number;
acceptedFileTypes?: string;
}
export function CloudinaryUpload({
onUploadSuccess,
onUploadError,
buttonText = 'Upload Image',
uploadPreset = 'jackerbox_uploads',
className,
buttonClassName,
multiple = false,
maxFiles = 10,
acceptedFileTypes = 'image/*',
}: CloudinaryUploadProps) {
const onDrop = useCallback(async (acceptedFiles: File[]) => {
if (acceptedFiles.length === 0) return;
try {
const cloudName = process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME;
if (!cloudName) {
throw new Error('Cloudinary cloud name is not defined');
}
const uploads = acceptedFiles.map(async (file) => {
const formData = new FormData();
formData.append('file', file);
formData.append('upload_preset', uploadPreset);
const response = await fetch(
`https://api.cloudinary.com/v1_1/${cloudName}/image/upload`,
{
method: 'POST',
body: formData,
}
);
if (!response.ok) {
throw new Error(`Upload failed: ${response.statusText}`);
}
return await response.json();
});
const results = await Promise.all(uploads);
if (onUploadSuccess) {
if (multiple) {
onUploadSuccess(results);
} else {
onUploadSuccess(results[0]);
}
}
} catch (error) {
console.error('Error uploading to Cloudinary:', error);
if (onUploadError) {
onUploadError(error);
}
}
}, [onUploadSuccess, onUploadError, uploadPreset, multiple]);
const { getRootProps, getInputProps, isDragActive } = useDropzone({
onDrop,
accept: {
'image/*': ['.jpeg', '.jpg', '.png', '.gif', '.webp']
},
multiple,
maxFiles
});
return (
<div
{...getRootProps()}
className={cn(
'border-2 border-dashed rounded-lg p-6 cursor-pointer transition-colors',
isDragActive ? 'border-blue-500 bg-blue-50' : 'border-gray-300 hover:border-gray-400',
className
)}
>
<input {...getInputProps()} />
<div className="text-center">
{isDragActive ? (
<p>Drop the files here ...</p>
) : (
<>
<p className="mb-2">Drag & drop files here, or click to select</p>
<button
type="button"
className={cn(
"px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700",
buttonClassName
)}
>
{buttonText}
</button>
</>
)}
</div>
</div>
);
}
EOL
# Create dynamic export files for protected routes
mkdir -p src/app/routes/dashboard
echo "export const dynamic = 'force-dynamic';" > src/app/routes/dashboard/dynamic.js
mkdir -p src/app/routes/admin
echo "export const dynamic = 'force-dynamic';" > src/app/routes/admin/dynamic.js
mkdir -p src/app/routes/equipment/new
echo "export const dynamic = 'force-dynamic';" > src/app/routes/equipment/new/dynamic.js
mkdir -p src/app/routes/profile
echo "export const dynamic = 'force-dynamic';" > src/app/routes/profile/dynamic.js
mkdir -p src/app/routes/rentals
echo "export const dynamic = 'force-dynamic';" > src/app/routes/rentals/dynamic.js
mkdir -p src/app/routes/messages
echo "export const dynamic = 'force-dynamic';" > src/app/routes/messages/dynamic.js
# Verify that the components were created
echo "Verifying UI components..."
if [ -f "src/components/ui/button.tsx" ] && \
[ -f "src/components/ui/card.tsx" ] && \
[ -f "src/components/ui/alert.tsx" ] && \
[ -f "src/components/ui/cloudinary-image.tsx" ] && \
[ -f "src/components/ui/cloudinary-upload.tsx" ]; then
echo "UI components created successfully!"
else
echo "Error: Some UI components are missing!"
ls -la src/components/ui/
fi
# Verify that the utils file was created
if [ -f "src/lib/utils.ts" ]; then
echo "Utils file created successfully!"
else
echo "Error: Utils file is missing!"
ls -la src/lib/
fi
echo "Dynamic exports created successfully!"