forked from elliotBraem/efizzybot
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathBasicInformationForm.tsx
More file actions
165 lines (155 loc) · 5.12 KB
/
BasicInformationForm.tsx
File metadata and controls
165 lines (155 loc) · 5.12 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
import { useAuth } from "../contexts/auth-context";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import { z } from "zod";
import { useFeedCreationStore } from "../store/feed-creation-store";
import { ImageUpload } from "./ImageUpload";
import { Button } from "./ui/button";
import {
Form,
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "./ui/form";
import { Input } from "./ui/input";
import { Textarea } from "./ui/textarea";
const BasicInformationFormSchema = z.object({
profileImage: z.string().optional(),
feedName: z.string().min(3, "Feed name must be at least 3 characters"),
description: z.string().min(10, "Description must be at least 10 characters"),
hashtags: z.string().min(1, "Please provide at least one hashtag"),
});
type FormValues = z.infer<typeof BasicInformationFormSchema>;
export default function BasicInformationForm() {
const { isSignedIn, handleSignIn } = useAuth();
const {
profileImage: storedProfileImage,
name,
description,
hashtags,
setBasicInfo,
} = useFeedCreationStore();
const form = useForm<FormValues>({
resolver: zodResolver(BasicInformationFormSchema),
defaultValues: {
profileImage: storedProfileImage || "",
feedName: feedName || "",
description: description || "",
hashtags: hashtags || "",
},
});
const onSubmit = (data: FormValues) => {
setBasicInfo({
...data,
createdAt: new Date(),
});
};
return (
<div>
{isSignedIn ? (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
{/* Image Upload */}
<FormField
control={form.control}
name="profileImage"
render={({ field }) => (
<FormItem>
<FormControl>
<ImageUpload
label="Profile Image"
initialImageUrl={field.value || null}
onUploadSuccess={(_ipfsHash, ipfsUrl) => {
field.onChange(ipfsUrl);
setBasicInfo({ profileImage: ipfsUrl });
}}
recommendedText="Recommended: Square, at least 400x400px. This will be your feed's avatar."
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
{/* Feed Name */}
<FormField
control={form.control}
name="feedName"
render={({ field }) => (
<FormItem>
<FormLabel>Feed Name</FormLabel>
<FormControl>
<Input
placeholder="Name of your feed"
required
{...field}
onChange={(e) => {
field.onChange(e);
setBasicInfo({ feedName: e.target.value });
}}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
{/* Description */}
<FormField
control={form.control}
name="description"
render={({ field }) => (
<FormItem>
<FormLabel>Description</FormLabel>
<FormControl>
<Textarea
placeholder="Description"
className="min-h-[100px]"
required
{...field}
onChange={(e) => {
field.onChange(e);
setBasicInfo({ description: e.target.value });
}}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
{/* Hashtags */}
<FormField
control={form.control}
name="hashtags"
render={({ field }) => (
<FormItem>
<FormLabel>Hashtag (without #)</FormLabel>
<FormControl>
<Input
placeholder="Tag"
required
{...field}
onChange={(e) => {
field.onChange(e);
setBasicInfo({ hashtags: e.target.value });
}}
/>
</FormControl>
<FormMessage />
<p className="text-sm font-normal text-[#64748b]">
This will be used as a unique identifier for your feed.
</p>
</FormItem>
)}
/>
</form>
</Form>
) : (
<div className="flex flex-col items-center justify-center py-10">
<p className="mb-4 text-gray-600">Please login to create a feed</p>
<Button onClick={handleSignIn}>Login</Button>
</div>
)}
</div>
);
}