Merge branch 'birthday-input' into 'develop'

Use BirthdayInput on Edit profile page

See merge request soapbox-pub/soapbox-fe!1462
This commit is contained in:
marcin mikołajczak 2022-05-27 21:32:49 +00:00
commit 79a7b7998a
3 changed files with 10 additions and 11 deletions

View file

@ -58,7 +58,6 @@ const RegistrationForm: React.FC<IRegistrationForm> = ({ inviteToken }) => {
const [usernameUnavailable, setUsernameUnavailable] = useState(false); const [usernameUnavailable, setUsernameUnavailable] = useState(false);
const [passwordConfirmation, setPasswordConfirmation] = useState(''); const [passwordConfirmation, setPasswordConfirmation] = useState('');
const [passwordMismatch, setPasswordMismatch] = useState(false); const [passwordMismatch, setPasswordMismatch] = useState(false);
const [birthday, setBirthday] = useState<Date | undefined>(undefined);
const source = useRef(axios.CancelToken.source()); const source = useRef(axios.CancelToken.source());
@ -111,8 +110,8 @@ const RegistrationForm: React.FC<IRegistrationForm> = ({ inviteToken }) => {
setPasswordMismatch(!passwordsMatch()); setPasswordMismatch(!passwordsMatch());
}; };
const onBirthdayChange = (newBirthday: Date) => { const onBirthdayChange = (birthday: string) => {
setBirthday(newBirthday); updateParams({ birthday });
}; };
const launchModal = () => { const launchModal = () => {
@ -187,10 +186,6 @@ const RegistrationForm: React.FC<IRegistrationForm> = ({ inviteToken }) => {
if (inviteToken) { if (inviteToken) {
params.set('token', inviteToken); params.set('token', inviteToken);
} }
if (birthday) {
params.set('birthday', new Date(birthday.getTime() - (birthday.getTimezoneOffset() * 60000)).toISOString().slice(0, 10));
}
}); });
setSubmissionLoading(true); setSubmissionLoading(true);
@ -291,7 +286,7 @@ const RegistrationForm: React.FC<IRegistrationForm> = ({ inviteToken }) => {
{birthdayRequired && ( {birthdayRequired && (
<BirthdayInput <BirthdayInput
value={birthday} value={params.get('birthday')}
onChange={onBirthdayChange} onChange={onBirthdayChange}
required required
/> />

View file

@ -4,6 +4,7 @@ import { defineMessages, useIntl, FormattedMessage } from 'react-intl';
import { updateNotificationSettings } from 'soapbox/actions/accounts'; import { updateNotificationSettings } from 'soapbox/actions/accounts';
import { patchMe } from 'soapbox/actions/me'; import { patchMe } from 'soapbox/actions/me';
import snackbar from 'soapbox/actions/snackbar'; import snackbar from 'soapbox/actions/snackbar';
import BirthdayInput from 'soapbox/components/birthday_input';
import List, { ListItem } from 'soapbox/components/list'; import List, { ListItem } from 'soapbox/components/list';
import { useAppSelector, useAppDispatch, useOwnAccount, useFeatures } from 'soapbox/hooks'; import { useAppSelector, useAppDispatch, useOwnAccount, useFeatures } from 'soapbox/hooks';
import { normalizeAccount } from 'soapbox/normalizers'; import { normalizeAccount } from 'soapbox/normalizers';
@ -242,6 +243,10 @@ const EditProfile: React.FC = () => {
}; };
}; };
const handleBirthdayChange = (date: string) => {
updateData('birthday', date);
};
const handleHideNetworkChange: React.ChangeEventHandler<HTMLInputElement> = e => { const handleHideNetworkChange: React.ChangeEventHandler<HTMLInputElement> = e => {
const hide = e.target.checked; const hide = e.target.checked;
@ -325,10 +330,9 @@ const EditProfile: React.FC = () => {
<FormGroup <FormGroup
labelText={<FormattedMessage id='edit_profile.fields.birthday_label' defaultMessage='Birthday' />} labelText={<FormattedMessage id='edit_profile.fields.birthday_label' defaultMessage='Birthday' />}
> >
<Input <BirthdayInput
type='text'
value={data.birthday} value={data.birthday}
onChange={handleTextChange('birthday')} onChange={handleBirthdayChange}
/> />
</FormGroup> </FormGroup>
)} )}