Skip to content
Snippets Groups Projects
Commit 9ed18e18 authored by Bjarke Madsen's avatar Bjarke Madsen
Browse files

Add back old validatewebsiteurl for old surveys

Add navigation menu to survey pages for admins
parent b571fdc9
Branches
Tags
No related merge requests found
import React, { useEffect, useState, useCallback } from "react";
import React, { useEffect, useState, useCallback, useContext } from "react";
import { Container } from "react-bootstrap";
import toast, { Toaster } from "react-hot-toast";
import { Model, Serializer } from "survey-core";
......@@ -12,7 +12,8 @@ import './survey.scss';
import useMatomo from "../matomo/UseMatomo";
import { FunctionFactory } from "survey-core";
import { validationFunctions } from "./validation/validation";
import SurveySidebar from "./management/SurveySidebar";
import { userContext } from "../providers/UserProvider";
interface ValidationQuestion {
name?: string;
......@@ -25,6 +26,28 @@ const questionOverrides = {
data_protection_contact: (...args) => true, // don't validate the contact field, anything goes..
}
function oldValidateWebsiteUrl(params) {
let value = params[0];
if ((value == undefined || value == null || value == '')) {
return true;
}
try {
value = value.trim();
if (value.includes(" ")) {
return false;
}
// if there's not a protocol, add one for the test
if (!value.includes(":/")) {
value = "https://" + value;
}
const url = new URL(value);
return !!url
} catch (err) {
return false;
}
}
function validateQuestion(this: { question: ValidationQuestion, row?: any }, params: any) {
try {
const question = this.question;
......@@ -58,22 +81,27 @@ function validateQuestion(this: { question: ValidationQuestion, row?: any }, par
}
}
Serializer.addProperty("itemvalue", "customDescription:text");
Serializer.addProperty("question", "hideCheckboxLabels:boolean");
function SurveyContainerComponent({ loadFrom }) {
const [surveyModel, setSurveyModel] = useState<Model>(); // note that this is never updated and we abuse that fact by adding extra state to the surveyModel
const { year, nren } = useParams(); // nren stays empty for inspect and try
const [error, setError] = useState<string>('loading survey...');
const { user } = useContext(userContext);
const loggedIn = !!user.id;
const isAdmin = loggedIn ? user.permissions.admin : false;
if (!FunctionFactory.Instance.hasFunction("validateQuestion")) {
FunctionFactory.Instance.register("validateQuestion", validateQuestion);
}
if (!FunctionFactory.Instance.hasFunction("validateWebsiteUrl")) {
FunctionFactory.Instance.register("validateWebsiteUrl", oldValidateWebsiteUrl);
}
const { trackPageView } = useMatomo();
const beforeUnloadListener = useCallback((event) => {
......@@ -276,13 +304,16 @@ function SurveyContainerComponent({ loadFrom }) {
}
return (
<Container className="survey-container">
<Toaster />
<Prompt message="Are you sure you want to leave this page? Information you've entered may not be saved." when={() => { return surveyModel.mode == 'edit' && !!nren; }} onPageExit={onPageExitThroughRouter} />
<SurveyNavigationComponent surveyModel={surveyModel} surveyActions={surveyActions} year={year} nren={nren}>
<SurveyComponent surveyModel={surveyModel} />
</SurveyNavigationComponent>
</Container>
<>
{isAdmin ? <SurveySidebar /> : null}
<Container className="survey-container">
<Toaster />
<Prompt message="Are you sure you want to leave this page? Information you've entered may not be saved." when={() => { return surveyModel.mode == 'edit' && !!nren; }} onPageExit={onPageExitThroughRouter} />
<SurveyNavigationComponent surveyModel={surveyModel} surveyActions={surveyActions} year={year} nren={nren}>
<SurveyComponent surveyModel={surveyModel} />
</SurveyNavigationComponent>
</Container>
</>
);
}
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment