Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up GenderSelector #10679

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,16 @@ import { QueryClient, useQuery } from '@tanstack/react-query';
import _ from 'lodash';
import I18n from '../../lib/i18n';
import { apiV0Urls, contactEditProfileActionUrl } from '../../lib/requests/routes.js.erb';
import { genders } from '../../lib/wca-data.js.erb';
import Loading from '../Requests/Loading';
import Errored from '../Requests/Errored';
import useSaveAction from '../../lib/hooks/useSaveAction';
import { fetchJsonOrError } from '../../lib/requests/fetchWithAuthenticityToken';
import UtcDatePicker from '../wca/UtcDatePicker';
import CountrySelector from '../CountrySelector/CountrySelector';
import GenderSelector from '../GenderSelector/GenderSelector';

const CONTACT_EDIT_PROFILE_FORM_QUERY_CLIENT = new QueryClient();

const genderOptions = _.map(genders.byId, (gender) => ({
key: gender.id,
text: gender.name,
value: gender.id,
}));

export default function EditProfileForm({
wcaId,
onContactSuccess,
Expand Down Expand Up @@ -103,11 +97,9 @@ export default function EditProfileForm({
countryIso2={editedProfileDetails?.country_iso2}
onChange={handleFormChange}
/>
<Form.Select
options={genderOptions}
label={I18n.t('activerecord.attributes.user.gender')}
<GenderSelector
name="gender"
value={editedProfileDetails?.gender}
gender={editedProfileDetails?.gender}
onChange={handleFormChange}
/>
<Form.Field
Expand Down
12 changes: 10 additions & 2 deletions app/webpacker/components/GenderSelector/GenderSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@ import _ from 'lodash';
import { Form } from 'semantic-ui-react';

import { genders } from '../../lib/wca-data.js.erb';
import I18n from '../../lib/i18n';

const genderOptions = _.map(genders.byId, (gender) => ({
key: gender.id,
text: gender.name,
value: gender.id,
}));

function GenderSelector({ gender, onChange }) {
function GenderSelector({
name,
gender,
onChange,
disabled = false,
}) {
return (
<Form.Select
label="Gender"
name={name}
label={I18n.t('activerecord.attributes.user.gender')}
value={gender}
options={genderOptions}
onChange={onChange}
disabled={disabled}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@ import { adminCheckRecordsUrl, apiV0Urls } from '../../../../lib/requests/routes
import useSaveAction from '../../../../lib/hooks/useSaveAction';
import Loading from '../../../Requests/Loading';
import I18n from '../../../../lib/i18n';
import { genders, countries } from '../../../../lib/wca-data.js.erb';
import { countries } from '../../../../lib/wca-data.js.erb';
import useLoadedData from '../../../../lib/hooks/useLoadedData';
import Errored from '../../../Requests/Errored';
import UtcDatePicker from '../../../wca/UtcDatePicker';

const genderOptions = _.map(genders.byId, (gender) => ({
key: gender.id,
text: gender.name,
value: gender.id,
}));
import GenderSelector from '../../../GenderSelector/GenderSelector';

const countryOptions = _.map(countries.byIso2, (country) => ({
key: country.iso2,
Expand Down Expand Up @@ -144,12 +139,10 @@ export default function EditPersonForm({ wcaId, onSuccess, showDestroyButton = f
value={editedUserDetails?.representing || ''}
onChange={handleFormChange}
/>
<Form.Select
options={genderOptions}
label={I18n.t('activerecord.attributes.user.gender')}
<GenderSelector
name="gender"
disabled={!editedUserDetails}
value={editedUserDetails?.gender || ''}
gender={editedUserDetails?.gender || ''}
onChange={handleFormChange}
/>
<Form.Field
Expand Down
Loading