Skip to content

Commit

Permalink
Merge pull request #15 from City-of-Turku/develop
Browse files Browse the repository at this point in the history
Release v1.0.0
  • Loading branch information
juhomakkonen authored Apr 18, 2024
2 parents 4ea25ac + 87f0806 commit 80d672a
Show file tree
Hide file tree
Showing 22 changed files with 390 additions and 200 deletions.
2 changes: 0 additions & 2 deletions src/components/Buttons/HomeButton/HomeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useIntl } from 'react-intl';
import { Link } from 'react-router-dom';
import { useAppDispatch, useAppSelector } from '../../../hooks/reduxHooks';
import userSlice from '../../../redux/slices/userSlice';
import { logoutUser } from '../../../utils/mobilityProfileAPI';

const HomeButton = () => {
const intl = useIntl();
Expand All @@ -17,7 +16,6 @@ const HomeButton = () => {

const endPoll = () => {
if (token?.length) {
logoutUser(token);
setIsLoggedIn(false);
}
return;
Expand Down
1 change: 0 additions & 1 deletion src/components/Buttons/LinkButton/LinkButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const LinkButton = ({ urlValue, translationId, isActive }: LinkButtonProps) => {
role="button"
type="button"
disabled={!isActive}
aria-disabled={!isActive}
className="button-primary p-2"
aria-label={intl.formatMessage({ id: translationId })}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,5 @@ describe('<LinkButton />', () => {
expect(button[0].getAttribute('aria-label')).toContain(
finnishTranslations['app.buttons.link.summary'],
);
expect(button[0].getAttribute('aria-disabled')).toEqual('false');
});
});
20 changes: 18 additions & 2 deletions src/components/Content/Content.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
import React from 'react';
import { useAppSelector } from '../../hooks/reduxHooks';
import HomeButton from '../Buttons/HomeButton/HomeButton';
import ErrorComponent from '../Errors/ErrorComponent/ErrorComponent';
import Loading from '../Loading/Loading';
import QuestionForm from '../QuestionForm/QuestionForm';

const Content = () => {
const { isLoggedIn } = useAppSelector((state) => state.user);
const { isLoggedIn, isError } = useAppSelector((state) => state.user);

return <div className="content-inner">{isLoggedIn ? <QuestionForm /> : <Loading />}</div>;
const renderSecondaryContent = () => {
if (isError) {
return (
<ErrorComponent translationId="app.result.error">
<HomeButton />
</ErrorComponent>
);
} else {
return <Loading />;
}
};

return (
<div className="content-inner">{isLoggedIn ? <QuestionForm /> : renderSecondaryContent()}</div>
);
};

export default Content;
23 changes: 10 additions & 13 deletions src/components/Forms/EmailForm/EmailForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useIntl } from 'react-intl';
import { useAppSelector } from '../../../hooks/reduxHooks';
import { EmailField } from '../../../types';
import { postSubscribeInfo } from '../../../utils/mobilityProfileAPI';
import ErrorText from '../../Typography/ErrorText/ErrorText';
import TextBasic from '../../Typography/TextBasic/TextBasic';

const EmailForm = () => {
Expand All @@ -15,9 +14,7 @@ const EmailForm = () => {
const intl = useIntl();

const { user } = useAppSelector((state) => state);
const resultId = user?.profileResult?.id;
const userId = user?.userId;
const token = user?.csrfToken;

const registerLink = 'https://rekisteri.turku.fi/Saabe_data';

Expand All @@ -33,7 +30,7 @@ const EmailForm = () => {

const onSubmit: SubmitHandler<EmailField> = (data) => {
if (userId?.length) {
postSubscribeInfo(data.email, resultId, setHasUserAnswered, setIsApiError, token);
postSubscribeInfo(data.email, userId, setHasUserAnswered, setIsApiError);
}
};

Expand All @@ -60,6 +57,7 @@ const EmailForm = () => {
</label>
<input
type="email"
id="email"
placeholder={intl.formatMessage({ id: 'app.form.email.label' })}
{...register('email', {
required: true,
Expand All @@ -80,18 +78,17 @@ const EmailForm = () => {
</div>
)}
<div className="mb-2 center-text">
<Button
type="submit"
role="button"
disabled={hasUserAnswered}
aria-disabled={hasUserAnswered}
className="input-submit"
>
<Button type="submit" role="button" disabled={hasUserAnswered} className="input-submit">
{intl.formatMessage({ id: 'app.input.submit.newsletter' })}
</Button>
{hasUserAnswered ? <TextBasic translationId="app.result.newsletter.success" /> : null}
{hasUserAnswered ? (
<TextBasic
translationId={
isApiError ? 'app.result.newsletter.error' : 'app.result.newsletter.success'
}
/>
) : null}
</div>
{isApiError ? <ErrorText /> : null}
</form>
</div>
</div>
Expand Down
Loading

0 comments on commit 80d672a

Please sign in to comment.