Skip to content

Commit

Permalink
fix(info co): fix info co length limit
Browse files Browse the repository at this point in the history
  • Loading branch information
emile-bex committed Jul 27, 2023
1 parent 9c90079 commit 4b28d25
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
2 changes: 2 additions & 0 deletions src/components/forms/GenericField.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ export const GenericField = ({
case 'radio-new': {
return (
<RadioNew
limit={data.limit}
options={data.options}
id={`${formId}-${data.id}`}
name={data.name}
Expand All @@ -483,6 +484,7 @@ export const GenericField = ({
case 'radio-async-new': {
return (
<RadioAsyncNew
limit={data.limit}
loadOptions={async () => {
const options = await data.loadOptions();
updateFieldOptions({ [data.id]: options });
Expand Down
1 change: 1 addition & 0 deletions src/components/forms/schema/formCandidateInscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export const formCandidateInscription = {
title:
'Selectionnez la date de la prochaine réunion d’information à laquelle vous souhaitez participer :',
component: 'radio-async-new',
limit: 7,
dynamicFilter: (getValue) => {
return ANTENNE_INFO.find((antenne) => {
return antenne.dpt === getValue('location');
Expand Down
55 changes: 30 additions & 25 deletions src/components/utils/Inputs/Radio/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function Radio({
errorMessage,
hidden,
value: valueProp,
limit = options.length,
}: RadioComponentProps) {
const [checkedRadio, setCheckedRadio] = useState<number>();

Expand Down Expand Up @@ -53,31 +54,35 @@ export function Radio({
<>
<legend>{legend}</legend>
<div className="inputs-container">
{options.map(({ inputId, label, value, filterData }, i) => {
if (filter && filterData && filter !== filterData) return null;
if (!inputId) inputId = `radio-${value.replace(/\s+/g, '')}`;
return (
<label
htmlFor={inputId}
className={i === checkedRadio ? 'checked' : ''}
key={`${i}-${uuidValue}`}
onClick={(event) => event.stopPropagation()}
>
<input
type="radio"
value={value}
id={inputId}
data-testid={inputId}
name={name}
checked={i === checkedRadio}
onChange={(e) => {
onHandleRadio(i, e);
}}
/>
{label}
</label>
);
})}
{options
.filter(({ filterData }) => {
return !(filter && filterData && filter !== filterData);
})
.slice(0, limit)
.map(({ inputId, label, value }, i) => {
if (!inputId) inputId = `radio-${value.replace(/\s+/g, '')}`;
return (
<label
htmlFor={inputId}
className={i === checkedRadio ? 'checked' : ''}
key={`${i}-${uuidValue}`}
onClick={(event) => event.stopPropagation()}
>
<input
type="radio"
value={value}
id={inputId}
data-testid={inputId}
name={name}
checked={i === checkedRadio}
onChange={(e) => {
onHandleRadio(i, e);
}}
/>
{label}
</label>
);
})}
</div>
</>
)}
Expand Down
2 changes: 2 additions & 0 deletions src/components/utils/Inputs/Radio/Radio.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface RadioAsyncComponentProps {
hidden?: boolean;
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
value: string;
limit?: number;
}

export interface RadioComponentProps {
Expand All @@ -29,4 +30,5 @@ export interface RadioComponentProps {
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;

value: string;
limit?: number;
}
2 changes: 2 additions & 0 deletions src/components/utils/Inputs/Radio/RadioAsync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function RadioAsync({
errorMessage,
hidden,
value,
limit,
}: RadioAsyncComponentProps) {
const [options, setOptions] = useState([]);

Expand All @@ -31,6 +32,7 @@ export function RadioAsync({
onChange={onChange}
filter={filter}
options={options}
limit={limit}
hidden={hidden}
errorMessage={errorMessage}
value={value}
Expand Down

0 comments on commit 4b28d25

Please sign in to comment.