Skip to content

Commit d0cd92e

Browse files
committed
refactor: update JudgingTab and RewardsTab components
- Removed the Administrators section from JudgingTab for a cleaner interface. - Enhanced RewardsTab to support real-time updates for prize amounts using the useWatch hook. - Adjusted platform fee calculation from 2% to 4% and set default prize amounts to 0 for new tiers. - Improved user experience by ensuring immediate feedback on prize tier changes.
1 parent 71b8692 commit d0cd92e

2 files changed

Lines changed: 23 additions & 92 deletions

File tree

components/organization/hackathons/new/tabs/JudgingTab.tsx

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import {
2424
X,
2525
Minus,
2626
GripVertical,
27-
Info,
28-
LucideArrowUpRight,
2927
Sparkles,
3028
ChevronDown,
3129
ChevronUp,
@@ -46,7 +44,6 @@ import {
4644
} from '@dnd-kit/sortable';
4745
import { useSortable } from '@dnd-kit/sortable';
4846
import { CSS } from '@dnd-kit/utilities';
49-
import Link from 'next/link';
5047
import { Separator } from '@/components/ui/separator';
5148
import {
5249
Collapsible,
@@ -465,37 +462,6 @@ export default function JudgingTab({
465462
}
466463
};
467464

468-
const administrators = [
469-
{
470-
id: '1',
471-
name: 'Brooklyn Simmons',
472-
email: 'debbie.baker@example.com',
473-
role: 'OWNER',
474-
avatar: '/api/placeholder/40/40',
475-
},
476-
{
477-
id: '2',
478-
name: 'Annette Black',
479-
email: '@verydarkman',
480-
role: 'ADMIN',
481-
avatar: '/api/placeholder/40/40',
482-
},
483-
{
484-
id: '3',
485-
name: 'Cameron Williamson',
486-
email: 'cameron@example.com',
487-
role: 'ADMIN',
488-
avatar: '/api/placeholder/40/40',
489-
},
490-
{
491-
id: '4',
492-
name: 'Jane Doe',
493-
email: 'jane@example.com',
494-
role: 'ADMIN',
495-
avatar: '/api/placeholder/40/40',
496-
},
497-
];
498-
499465
return (
500466
<Form {...form}>
501467
<form onSubmit={form.handleSubmit(onSubmit)} className='space-y-8'>
@@ -632,54 +598,6 @@ export default function JudgingTab({
632598
)}
633599
</div>
634600

635-
<div>
636-
<h3 className='text-sm'>
637-
Administrators <span className='text-error-400'>*</span>
638-
</h3>
639-
<p className='mt-1 mb-3 text-sm text-gray-500'>
640-
The admins and the owner of your organization have full permissions
641-
to manage this hackathon. See below.
642-
</p>
643-
<div className='bg-background-card mt-3 rounded-[12px] border border-gray-900 p-6'>
644-
<div className='space-y-4'>
645-
{administrators.map(admin => (
646-
<div
647-
key={admin.id}
648-
className='flex items-center justify-between py-3'
649-
>
650-
<div className='flex items-center gap-3'>
651-
<div className='flex h-10 w-10 items-center justify-center rounded-full bg-gray-800 font-medium text-white'>
652-
{admin.name.charAt(0)}
653-
</div>
654-
<div>
655-
<p className='text-sm font-medium text-white'>
656-
{admin.name}
657-
</p>
658-
<p className='text-xs text-gray-500'>{admin.email}</p>
659-
</div>
660-
</div>
661-
<span className='text-xs font-medium text-gray-400'>
662-
{admin.role}
663-
</span>
664-
</div>
665-
))}
666-
</div>
667-
</div>
668-
<div className='mt-4 flex items-start gap-2 rounded-[12px] bg-[#DBF936]/12 p-4'>
669-
<Info className='mt-0.5 h-4 w-4 flex-shrink-0 text-[#DBF936]' />
670-
<p className='flex items-center gap-1 text-xs text-white'>
671-
To add, remove, or edit admin, visit your{' '}
672-
<Link
673-
href='/organization/dashboard'
674-
className='flex items-center gap-1 text-[#DBF936] underline'
675-
>
676-
organization dashboard{' '}
677-
<LucideArrowUpRight className='h-4 w-4' />
678-
</Link>
679-
</p>
680-
</div>
681-
</div>
682-
683601
<BoundlessButton type='submit' size='xl' disabled={isLoading}>
684602
{isLoading ? 'Saving...' : 'Continue'}
685603
</BoundlessButton>

components/organization/hackathons/new/tabs/RewardsTab.tsx

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
FormItem,
99
FormMessage,
1010
} from '@/components/ui/form';
11-
import { useForm, useFieldArray } from 'react-hook-form';
11+
import { useForm, useFieldArray, useWatch } from 'react-hook-form';
1212
import { zodResolver } from '@hookform/resolvers/zod';
1313
import { Input } from '@/components/ui/input';
1414
import { Textarea } from '@/components/ui/textarea';
@@ -149,6 +149,13 @@ const PrizeTierComponent = ({
149149
{...field}
150150
type='number'
151151
placeholder='0'
152+
value={field.value || '0'}
153+
onChange={e => {
154+
const value = e.target.value;
155+
// Update field value immediately for real-time calculation
156+
field.onChange(value === '' ? '0' : value);
157+
}}
158+
onBlur={field.onBlur}
152159
className='h-11 border-zinc-800 bg-zinc-900/50 pr-16 pl-7 text-right font-medium text-white placeholder:text-zinc-600'
153160
/>
154161
<div className='absolute top-1/2 right-3 -translate-y-1/2 text-xs text-zinc-500'>
@@ -232,7 +239,7 @@ const PrizeSummary = ({
232239
</div>
233240

234241
<div className='flex items-center justify-between text-xs'>
235-
<span className='text-zinc-500'>Platform Fee (2%)</span>
242+
<span className='text-zinc-500'>Platform Fee (4%)</span>
236243
<span className='text-zinc-400'>${formatCurrency(platformFee)}</span>
237244
</div>
238245

@@ -308,23 +315,23 @@ export default function RewardsTab({
308315
{
309316
id: `tier-${Date.now()}-1`,
310317
place: '1st Place',
311-
prizeAmount: '10000',
318+
prizeAmount: '0',
312319
description: '',
313320
currency: 'USDC',
314321
passMark: 80,
315322
},
316323
{
317324
id: `tier-${Date.now()}-2`,
318325
place: '2nd Place',
319-
prizeAmount: '5000',
326+
prizeAmount: '0',
320327
description: '',
321328
currency: 'USDC',
322329
passMark: 70,
323330
},
324331
{
325332
id: `tier-${Date.now()}-3`,
326333
place: '3rd Place',
327-
prizeAmount: '2500',
334+
prizeAmount: '0',
328335
description: '',
329336
currency: 'USDC',
330337
passMark: 50,
@@ -337,20 +344,26 @@ export default function RewardsTab({
337344
control: form.control,
338345
name: 'prizeTiers',
339346
});
340-
const prizeTiers = form.watch('prizeTiers');
341347

342-
// Calculate totals
348+
// Watch prizeTiers in real-time for immediate updates using useWatch hook
349+
const prizeTiers = useWatch({
350+
control: form.control,
351+
name: 'prizeTiers',
352+
defaultValue: form.getValues('prizeTiers') || [],
353+
});
354+
355+
// Calculate totals - updates in real-time as user types
343356
const totalPool = useMemo(() => {
344357
return prizeTiers.reduce((sum, tier) => {
345358
const amount = parseFloat(
346-
String(tier.prizeAmount).replace(/[^\d.-]/g, '')
359+
String(tier.prizeAmount || '0').replace(/[^\d.-]/g, '')
347360
);
348361
return sum + (isNaN(amount) || amount < 0 ? 0 : amount);
349362
}, 0);
350363
}, [prizeTiers]);
351364

352365
const platformFee = useMemo(
353-
() => Math.round(totalPool * 0.02 * 100) / 100,
366+
() => Math.round(totalPool * 0.04 * 100) / 100,
354367
[totalPool]
355368
);
356369
const totalFunds = useMemo(
@@ -364,7 +377,7 @@ export default function RewardsTab({
364377

365378
const applyPreset = (presetKey: keyof typeof PRIZE_PRESETS) => {
366379
const preset = PRIZE_PRESETS[presetKey];
367-
const baseAmount = totalPool || 10000;
380+
const baseAmount = totalPool || 0;
368381
const newTiers = preset.tiers.map((percentage, idx) => ({
369382
id: `tier-${Date.now()}-${idx}`,
370383
place: `${['1st', '2nd', '3rd', '4th', '5th'][idx]} Place`,

0 commit comments

Comments
 (0)