Skip to content

Commit

Permalink
Merge pull request #55 from InseeFr/fix/bouton_open_close
Browse files Browse the repository at this point in the history
call isSurveyOnline in Main and use response in menus/responseButton
  • Loading branch information
BettyB979 authored May 24, 2024
2 parents af167f3 + bcf55c8 commit 18911f3
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM nginx
FROM nginx:stable-alpine
COPY build /usr/share/nginx/html
RUN rm etc/nginx/conf.d/default.conf
COPY nginx-coleman-promotion.conf etc/nginx/conf.d/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "colempub",
"version": "1.1.1",
"version": "1.1.2",
"dependencies": {
"axios": "^0.19.2",
"bootstrap": "^3.3.7",
Expand Down
43 changes: 37 additions & 6 deletions src/components/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import AssistanceForm from 'components/forms/assistance-form';
import AssistanceRouter from 'components/forms/assistance-router';
import ControlEmailForm from 'components/forms/mail-modif';
import DonneesPersonnelles from './content/donnees-personnelles';

import { isSurveyOnLine } from 'utils/api';
import {
idExists,
getSurveyTitleById,
Expand All @@ -40,6 +40,9 @@ class Main extends React.Component {
showResponseButton: true,
showMinimalFooter: false,
id: match.params.id,
isSurveyOnLine: undefined,
messageSurveyOffline: "",
messageInfoSurveyOffline: ""
};
}

Expand Down Expand Up @@ -70,10 +73,31 @@ class Main extends React.Component {
}
};

fetchData = async () => {
try {
const response = await isSurveyOnLine(this.props.urlBackEnd)(this.state.id);
if (response.data && response.data.opened === false) {
this.setState({isSurveyOnLine: false})
this.setState({messageSurveyOffline: response.data.messageSurveyOffline})
this.setState({messageInfoSurveyOffline: response.data.messageInfoSurveyOffline})
} else {
this.setState({isSurveyOnLine: true})
}
} catch (error) {
console.error('Error checking survey online:', error);
this.setState({isSurveyOnLine: false})
}
};

componentDidMount = () => {
this.fetchData();
}


/* return */ render() {
const { urlBackEnd, match, urlMySurveys, keycloakAuth } = this.props;

const { id, showMenu, showResponseButton, showMinimalFooter } = this.state;
const { id, showMenu, showResponseButton, showMinimalFooter , isSurveyOnLine, messageSurveyOffline, messageInfoSurveyOffline} = this.state;

return (
<>
Expand Down Expand Up @@ -105,7 +129,7 @@ class Main extends React.Component {
)}
/>

{showMenu && <Menu id={id} link={urlBackEnd} />}
{showMenu && <Menu id={id} link={urlBackEnd} isSurveyOnLine={isSurveyOnLine} />}
<div className="row">
<div className="col-md-8 text-justify">
{/* <Route
Expand Down Expand Up @@ -215,14 +239,21 @@ render={routeProps => <ChangePasswordForm {...routeProps} urlBackEnd={urlBackEnd
component={routeProps => <Faq {...routeProps} enquete={id} />}
/>
{!showMinimalFooter ? (
<FooterMenu home={false} path={match.url} id={id} />
<FooterMenu home={false} path={match.url} id={id} isSurveyOnLine={isSurveyOnLine} />
) : (
<FooterMenu home path={match.url} id={id} />
<FooterMenu home path={match.url} id={id} isSurveyOnLine={isSurveyOnLine}/>
)}
</div>
</div>
<div className="col-md-4">
{showResponseButton && <ResponseButton id={id} urlBackEnd={urlBackEnd} />}
{showResponseButton &&
<ResponseButton
id={id}
isSurveyOnLine={isSurveyOnLine}
messageSurveyOffline={messageSurveyOffline}
messageInfoSurveyOffline={messageInfoSurveyOffline}
/>
}
</div>
</div>
</>
Expand Down
5 changes: 2 additions & 3 deletions src/components/template/footer-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { Navbar, Nav, NavItem } from 'react-bootstrap';
import { LinkContainer } from 'react-router-bootstrap';
import logoTwitter from 'img/common/logo-twitter.png';
import { urlInseeFr } from 'utils/properties';
import { isSurveyOnLine } from 'utils/api';

function FooterMenu({ path, home, id }) {
function FooterMenu({ path, home, id, isSurveyOnLine }) {
const [isDesktop, setIsDesktop] = useState(window.innerWidth > 767);
const updateFooterMenu = () => {
if (window.innerWidth <= 767) {
Expand Down Expand Up @@ -44,7 +43,7 @@ function FooterMenu({ path, home, id }) {
<LinkContainer to={`/${id}/faq`}>
<NavItem eventKey={1}>{`Questions/réponses`}</NavItem>
</LinkContainer>
{isSurveyOnLine(id) && (
{isSurveyOnLine && (
<LinkContainer to={`/${id}/contacter-assistance`}>
<NavItem eventKey={2}>{`Contacter l'assistance`}</NavItem>
</LinkContainer>
Expand Down
31 changes: 18 additions & 13 deletions src/components/template/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { Link } from 'react-router-dom';
import { urlInseeFr } from 'utils/properties';
import logoTwitter from 'img/common/logo-twitter.png';
import { getResultsMenuTitle, getSurveyDetailLink } from 'utils/read-content';
import { isSurveyOnLine } from 'utils/api';
import ReactLoading from 'react-loading';

function Menu({ id }) {
function Menu({ id, isSurveyOnLine }) {
const [isDesktop, setIsDesktop] = useState(window.innerWidth > 767);
const updateFooterMenu = () => {
if (window.innerWidth <= 767) {
Expand All @@ -35,16 +35,21 @@ function Menu({ id }) {
</Navbar.Header>
<Navbar.Collapse>
<Nav>
<NavItem
href={`/${id}/login`}
to={`/${id}/login`}
eventKey={1}
id="menuItemRepondre"
disabled={!isSurveyOnLine(id)}
>
{`Accéder au questionnaire`}
</NavItem>

{isSurveyOnLine === undefined ?
<NavItem style={{display: "flex", flexDirection: "column", alignItems: "center" }}>
<ReactLoading type="spin" color={`#0f417a`} width={"30px"} />
</NavItem>
:
<NavItem
href={`/${id}/login`}
to={`/${id}/login`}
eventKey={1}
id="menuItemRepondre"
disabled={!isSurveyOnLine}
>
{`Accéder au questionnaire`}
</NavItem>
}
<LinkContainer to={`/${id}/donnees-personnelles`}>
<NavItem eventKey={2}>{`Données personnelles`}</NavItem>
</LinkContainer>
Expand All @@ -66,7 +71,7 @@ function Menu({ id }) {
<NavItem eventKey={7} href={`/${id}/faq`}>
{`Questions/réponses`}
</NavItem>
{isSurveyOnLine(id) && (
{isSurveyOnLine && (
<NavItem eventKey={8} href={`/${id}/contacter-assistance`}>
{`Contacter l'assistance`}
</NavItem>
Expand Down
34 changes: 5 additions & 29 deletions src/components/template/response-button.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
import React, {useState, useEffect} from 'react';
import React from 'react';
import { Link } from 'react-router-dom';
import ReactLoading from 'react-loading';
import { isSurveyOnLine } from 'utils/api';

const ResponseButton = ({ id, urlBackEnd}) => {
const [surveyOnLine, setSurveyOnLine] = useState(undefined);
const [messageSurveyOffline, setMessageSurveyOffline] = useState("");
const [messageInfoSurveyOffline, setMessageInfoSurveyOffline] = useState("");

useEffect(() => {
const fetchData = async () => {
try {
const response = await isSurveyOnLine(urlBackEnd)(id);
if (response.data && response.data.opened === false) {
setSurveyOnLine(false);
setMessageSurveyOffline(response.data.messageSurveyOffline);
setMessageInfoSurveyOffline(response.data.messageInfoSurveyOffline);
} else {
setSurveyOnLine(true);
}
} catch (error) {
console.error('Error checking survey online:', error);
setSurveyOnLine(false);
}
};

fetchData();
}, [id, urlBackEnd]);
const ResponseButton = ({ id, isSurveyOnLine, messageSurveyOffline,messageInfoSurveyOffline}) => {

if(surveyOnLine === undefined) {
if(isSurveyOnLine === undefined) {
return (
<div className="center-block text-center">
<section style={{display: "flex", flexDirection: "column", alignItems: "center" }}>
Expand All @@ -44,12 +20,12 @@ const ResponseButton = ({ id, urlBackEnd}) => {
<section>
<h2>{`Répondre à l'enquête`}</h2>
<Link to={`/${id}/login`} tabIndex="-1">
<button type="button" className="btn btn-lg" id="accessButton" disabled={!surveyOnLine}>
<button type="button" className="btn btn-lg" id="accessButton" disabled={!isSurveyOnLine}>
{'Accéder au questionnaire'}
</button>
</Link>
<p />
{!surveyOnLine && (
{!isSurveyOnLine && (
<>
{messageSurveyOffline && <div className="surveyOver">{messageSurveyOffline}</div>}
{messageInfoSurveyOffline && <p>{messageInfoSurveyOffline}</p>}
Expand Down

0 comments on commit 18911f3

Please sign in to comment.