All files / features/events/components/event-settings GeneralForm.tsx

100% Statements 10/10
50% Branches 6/12
100% Functions 7/7
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                            1x 9x         9x   9x                                                                                                                                   9x                                                                                                                                                                 10x                               10x                               10x                               10x                               10x                                      
import { useFormContext, Controller } from 'react-hook-form'
import { useTranslation } from 'react-i18next'
import { Input } from '@core/components/ui/input'
import { Label } from '@core/components/ui/label'
import { Card, CardHeader, CardTitle, CardContent, CardDescription } from '@core/components/ui/card'
import {
    Select,
    SelectContent,
    SelectItem,
    SelectTrigger,
    SelectValue,
} from '@core/components/ui/select'
import { Checkbox } from '@core/components/ui/checkbox'
 
export const GeneralForm = () => {
    const { t } = useTranslation('common')
    const {
        register,
        control,
        formState: { errors },
    } = useFormContext()
 
    return (
        <div className="space-y-6">
            <Card
                style={{
                    backgroundColor: 'var(--admin-card-bg)',
                    borderColor: 'var(--admin-border-color)',
                }}
            >
                <CardHeader>
                    <CardTitle>
                        {t('event_settings.general.basic_details_title', 'Basic Details')}
                    </CardTitle>
                    <CardDescription>
                        {t(
                            'event_settings.general.basic_details_desc',
                            'Main information about your fundraising event.',
                        )}
                    </CardDescription>
                </CardHeader>
                <CardContent className="space-y-4">
                    <div className="grid gap-2">
                        <Label htmlFor="name">
                            {t('event_settings.general.event_name', 'Event Name')}
                        </Label>
                        <Input id="name" {...register('name')} />
                        {errors.name && (
                            <p className="text-sm text-red-500">{errors.name.message as string}</p>
                        )}
                    </div>
 
                    <div className="grid gap-2">
                        <Label htmlFor="description">
                            {t('event_settings.general.description', 'Description')}
                        </Label>
                        <textarea
                            id="description"
                            className="flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
                            {...register('description')}
                        />
                        {errors.description && (
                            <p className="text-sm text-red-500">
                                {errors.description.message as string}
                            </p>
                        )}
                    </div>
 
                    <div className="grid grid-cols-2 gap-4">
                        <div className="grid gap-2">
                            <Label htmlFor="slug">
                                {t('event_settings.general.url_slug', 'URL Slug')}
                            </Label>
                            <Input id="slug" {...register('slug')} />
                            {errors.slug && (
                                <p className="text-sm text-red-500">
                                    {errors.slug.message as string}
                                </p>
                            )}
                        </div>
                        <div className="grid gap-2">
                            <Label htmlFor="status">
                                {t('event_settings.general.status', 'Status')}
                            </Label>
                            <Controller
                                control={control}
                                name="status"
                                render={({ field }) => (
                                    <Select onValueChange={field.onChange} value={field.value}>
                                        <SelectTrigger>
                                            <SelectValue
                                                placeholder={t(
                                                    'event_settings.general.status_placeholder',
                                                    'Select status',
                                                )}
                                            />
                                        </SelectTrigger>
                                        <SelectContent>
                                            <SelectItem value="active">
                                                {t('admin_events.status.active', 'Active')}
                                            </SelectItem>
                                            <SelectItem value="draft">
                                                {t('admin_events.status.draft', 'Draft')}
                                            </SelectItem>
                                            <SelectItem value="closed">
                                                {t('admin_events.status.closed', 'Closed')}
                                            </SelectItem>
                                        </SelectContent>
                                    </Select>
                                )}
                            />
                            {errors.status && (
                                <p className="text-sm text-red-500">
                                    {errors.status.message as string}
                                </p>
                            )}
                        </div>
                    </div>
 
                    <div className="grid grid-cols-2 gap-4">
                        <div className="grid gap-2">
                            <Label htmlFor="goalAmount">
                                {t('event_settings.general.goal_amount', 'Fundraising Goal')}
                            </Label>
                            <Input id="goalAmount" type="number" {...register('goalAmount')} />
                            {errors.goalAmount && (
                                <p className="text-sm text-red-500">
                                    {errors.goalAmount.message as string}
                                </p>
                            )}
                        </div>
                        <div className="grid gap-2">
                            <Label htmlFor="date">
                                {t('event_settings.general.event_date', 'Event Date')}
                            </Label>
                            <Input id="date" type="date" {...register('date')} />
                            {errors.date && (
                                <p className="text-sm text-red-500">
                                    {errors.date.message as string}
                                </p>
                            )}
                        </div>
                    </div>
                </CardContent>
            </Card>
 
            <Card
                style={{
                    backgroundColor: 'var(--admin-card-bg)',
                    borderColor: 'var(--admin-border-color)',
                }}
            >
                <CardHeader>
                    <CardTitle>
                        {t('event_settings.general.form_config_title', 'Form Configuration')}
                    </CardTitle>
                    <CardDescription>
                        {t(
                            'event_settings.general.form_config_desc',
                            'Select additional fields to collect from donors.',
                        )}
                    </CardDescription>
                </CardHeader>
                <CardContent className="space-y-4">
                    <div className="flex items-center space-x-2">
                        <Controller
                            control={control}
                            name="formConfig.phone.enabled"
                            render={({ field }) => (
                                <Checkbox
                                    id="collectPhone"
                                    checked={field.value}
                                    onCheckedChange={field.onChange}
                                />
                            )}
                        />
                        <Label htmlFor="collectPhone">
                            {t('event_settings.general.collect_phone', 'Collect Phone Number')}
                        </Label>
                    </div>
                    <div className="flex items-center space-x-2">
                        <Controller
                            control={control}
                            name="formConfig.address.enabled"
                            render={({ field }) => (
                                <Checkbox
                                    id="collectAddress"
                                    checked={field.value}
                                    onCheckedChange={field.onChange}
                                />
                            )}
                        />
                        <Label htmlFor="collectAddress">
                            {t('event_settings.general.collect_address', 'Collect Address')}
                        </Label>
                    </div>
                    <div className="flex items-center space-x-2">
                        <Controller
                            control={control}
                            name="formConfig.company.enabled"
                            render={({ field }) => (
                                <Checkbox
                                    id="collectCompany"
                                    checked={field.value}
                                    onCheckedChange={field.onChange}
                                />
                            )}
                        />
                        <Label htmlFor="collectCompany">
                            {t('event_settings.general.collect_company', 'Collect Company Name')}
                        </Label>
                    </div>
                    <div className="flex items-center space-x-2">
                        <Controller
                            control={control}
                            name="formConfig.message.enabled"
                            render={({ field }) => (
                                <Checkbox
                                    id="collectMessage"
                                    checked={field.value}
                                    onCheckedChange={field.onChange}
                                />
                            )}
                        />
                        <Label htmlFor="collectMessage">
                            {t('event_settings.general.collect_message', 'Collect Message')}
                        </Label>
                    </div>
                    <div className="flex items-center space-x-2">
                        <Controller
                            control={control}
                            name="formConfig.anonymous.enabled"
                            render={({ field }) => (
                                <Checkbox
                                    id="allowAnonymous"
                                    checked={field.value}
                                    onCheckedChange={field.onChange}
                                />
                            )}
                        />
                        <Label htmlFor="allowAnonymous">
                            {t(
                                'event_settings.general.allow_anonymous',
                                'Allow Anonymous Donations',
                            )}
                        </Label>
                    </div>
                </CardContent>
            </Card>
        </div>
    )
}