import { Controller, useWatch } from 'react-hook-form'; import { Button, Form, Table } from 'react-bootstrap'; function patchRow(rows, index, patch) { const next = [...(rows || [])]; next[index] = { ...next[index], ...patch }; return next; } function emptyRow() { return { title: '', role: '', limit: 10, sort_order: 0, view_mode: 'versus', scope: 'domain', show_as: 'user', highlight_count: 0, highlight_color: '' }; } export default function RankRolesField({ field, control }) { const roles = field.roles || {}; const isTeam = useWatch({ control, name: 'leaderboard_roles_type' }) === 'team'; return ( { const rows = rhf.value || []; return (
{isTeam ? : null} {isTeam ? : null} {rows.map((row, index) => ( {isTeam ? ( ) : null} {isTeam ? ( ) : null} ))}
Title Role View ModeWhat to showShowLimit Highlight Color Sort Order
rhf.onChange(patchRow(rows, index, { title: e.target.value }))} /> rhf.onChange(patchRow(rows, index, { role: e.target.value }))} > {Object.entries(roles).map(([value, label]) => ( ))} rhf.onChange(patchRow(rows, index, { view_mode: e.target.value }))} > rhf.onChange(patchRow(rows, index, { show_as: e.target.value, ...(e.target.value === 'team' ? { role: '', scope: 'domain' } : {}), }))} > rhf.onChange(patchRow(rows, index, { scope: e.target.value }))} > rhf.onChange(patchRow(rows, index, { limit: e.target.value }))} /> rhf.onChange(patchRow(rows, index, { highlight_count: e.target.value }))} /> rhf.onChange(patchRow(rows, index, { highlight_color: e.target.value }))} /> rhf.onChange(patchRow(rows, index, { sort_order: e.target.value }))} />
{rows.length === 0 ?
No rank roles
: null}
); }} /> ); }