updated welsh translations

This commit is contained in:
2023-05-23 10:38:03 +01:00
parent dc43d7f2b4
commit 275258562e
45 changed files with 677 additions and 7698 deletions
+7 -2
View File
@@ -2,6 +2,7 @@ import Document, { Html, Head, Main, NextScript } from "next/document";
import SkipLink from "../components/skiplink";
import { Tracking, TrackingNoScript } from "../components/tracking";
import { nanoid } from "nanoid";
import { setCookie } from "nookies";
class MyDocument extends Document {
static async getInitialProps(ctx) {
@@ -19,12 +20,16 @@ class MyDocument extends Document {
useGATracking = false;
}
setCookie(ctx, "pedw_locale", ctx.locale, {
path: "/",
});
return { ...initialProps, useGATracking };
}
render() {
const googleTagManagerID = process.env.GOOGLE_TAG_MANAGER || null;
const { useGATracking } = this.props;
const { useGATracking, locale } = this.props;
const generatedNonce = nanoid();
@@ -39,7 +44,7 @@ class MyDocument extends Document {
csp += `style-src 'self' https://fonts.googleapis.com 'unsafe-inline' data:;`;
return (
<Html lang="en">
<Html lang={locale}>
<Head>
<meta httpEquiv="Content-Security-Policy" content={csp} />
{useGATracking && (
+10 -1
View File
@@ -39,7 +39,16 @@ function Error({ statusCode }, props) {
className="govuk-link"
onClick={() => {
window.localStorage.clear(),
destroyCookie({}, "pinsUser"),
destroyCookie(
null,
"next-auth.csrf-token"
),
destroyCookie(
null,
"next-auth.callback-url"
),
destroyCookie(null, "pedw_locale"),
destroyCookie(null, "pinsUser"),
session != null
? signOut({
callbackUrl: "/",
+217 -66
View File
@@ -16,77 +16,228 @@ import { PrismaAdapter } from "@next-auth/prisma-adapter";
import { PrismaClient } from "@prisma/client";
import nodemailer from "nodemailer";
import { consoleLogger } from "../../../actions";
import { useRouter } from "next/router";
import nookies from "nookies";
import { getCsrfToken } from "next-auth/react";
const prisma = new PrismaClient();
// For more information on each option (and a full list of options) go to
// https://next-auth.js.org/configuration/options
export default NextAuth({
// https://next-auth.js.org/configuration/providers
providers: [
EmailProvider({
// server: {
// host: process.env.EMAIL_SERVER_HOST,
// port: process.env.EMAIL_SERVER_PORT,
// auth: {
// user: process.env.EMAIL_SERVER_USER,
// pass: process.env.EMAIL_SERVER_PASSWORD,
// },
// },
// from: process.env.EMAIL_FROM,
maxAge: 10 * 60, // Magic links are valid for 10 min only
async sendVerificationRequest({
identifier: email,
url,
provider: { server, from },
}) {
const { host } = new URL(url);
const templateId = "b1b5704b-9bb8-4deb-a75c-d887ca902661";
const emailAddress = email;
const personalisation = {
"emailAddress": email,
"signInLink": url,
"linkExpiry": 10 * 60,
};
const reference = "PEDW-SIGNIN";
// export default NextAuth({
// // https://next-auth.js.org/configuration/providers
// providers: [
// EmailProvider({
// // server: {
// // host: process.env.EMAIL_SERVER_HOST,
// // port: process.env.EMAIL_SERVER_PORT,
// // auth: {
// // user: process.env.EMAIL_SERVER_USER,
// // pass: process.env.EMAIL_SERVER_PASSWORD,
// // },
// // },
// // from: process.env.EMAIL_FROM,
// maxAge: 10 * 60, // Magic links are valid for 10 min only
// async sendVerificationRequest({
// identifier: email,
// url,
// provider: { server, from },
// }) {
// const { host } = new URL(url);
// const templateId = "b1b5704b-9bb8-4deb-a75c-d887ca902661";
// const emailAddress = email;
// const personalisation = {
// "emailAddress": email,
// "signInLink": url,
// "linkExpiry": 10 * 60,
// };
// const reference = "PEDW-SIGNIN";
var NotifyClient =
require("notifications-node-client").NotifyClient;
// var NotifyClient =
// require("notifications-node-client").NotifyClient;
const notifyClient = new NotifyClient(
process.env.NOTIFY_API_KEY
);
// const notifyClient = new NotifyClient(
// process.env.NOTIFY_API_KEY
// );
await notifyClient
.sendEmail(templateId, emailAddress, {
personalisation: personalisation,
reference: reference,
// emailReplyToId: emailReplyToId,
})
//.then((response) => console.log(response))
.catch((err) => consoleLogger(err));
},
}),
],
adapter: PrismaAdapter(prisma),
secret: process.env.SECRET,
session: {
jwt: true,
pages: {},
theme: "dark",
debug: true,
},
pages: {
signIn: "/auth/signin",
//signOut: "/auth/signout",
error: "/auth/error", // Error code passed in query string as ?error=
verifyRequest: "/auth/verify-request", // (used for check email message)
newUser: "/account/register", // New users will be directed here on first sign in (leave the property out if not of interest)
},
callbacks: {
session: async (session, user) => {
//console.log(user);
return Promise.resolve(session);
// await notifyClient
// .sendEmail(templateId, emailAddress, {
// personalisation: personalisation,
// reference: reference,
// // emailReplyToId: emailReplyToId,
// })
// //.then((response) => console.log(response))
// .catch((err) => consoleLogger(err));
// },
// }),
// ],
// adapter: PrismaAdapter(prisma),
// secret: process.env.SECRET,
// session: {
// jwt: true,
// pages: {},
// theme: "dark",
// debug: true,
// },
// pages: {
// signIn: "/auth/signin",
// //signOut: "/auth/signout",
// error: "/auth/error", // Error code passed in query string as ?error=
// verifyRequest: "/auth/verify-request", // (used for check email message)
// newUser: "/account/register", // New users will be directed here on first sign in (leave the property out if not of interest)
// },
// callbacks: {
// session: async (session, user) => {
// //console.log(user);
// return Promise.resolve(session);
// },
// },
// });
const parseUrl = (url) => {
const defaultUrl = new URL(
$(
(locale == "cy"
? process.env.CY_API_ROOT
: process.env.NEXTAUTH_URL) + `/api/auth`
)
);
if (url && !url.startsWith("http")) {
url = `https://${url}`;
}
const _url = new URL(url ?? defaultUrl);
const path = (_url.pathname === "/" ? defaultUrl.pathname : _url.pathname)
// Remove trailing slash
.replace(/\/$/, "");
const base = `${_url.origin}${path}`;
return {
origin: _url.origin,
host: _url.host,
path,
base,
toString: () => base,
};
};
const authOptions = (locale, req) => {
//console.log(req.query.callbackUrl);
// let newURL = parseUrl(
// locale == "cy"
// ? "https://" + process.env.I18N_DOMAIN + ":3000"
// : process.env.NEXTAUTH_URL
// );
return {
providers: [
EmailProvider({
maxAge: 10 * 60, // Magic links are valid for 10 min only
async sendVerificationRequest({ identifier: email, url }) {
const { host, port, protocol, token, searchParams } =
new URL(url);
const templateId = "b1b5704b-9bb8-4deb-a75c-d887ca902661";
const templateIdcy = "0614ce53-cd5f-421f-a1a5-8c8486a9113a";
const emailAddress = email;
console.log("verifciation url", url);
let newURL =
locale == "cy"
? process.env.CY_API_ROOT
: process.env.NEXTAUTH_URL;
const csrfToken = await getCsrfToken({ req });
console.log(newURL, searchParams.get("token"));
const personalisation = {
"emailAddress": email,
"signInLink": url,
"signInLink":
newURL +
"/api/auth/callback/email?callbackUrl=" +
encodeURIComponent(newURL) +
"&token=" +
searchParams.get("token") +
"&email=" +
encodeURIComponent(email),
"linkExpiry": 10 * 60,
};
const reference = "PEDW-SIGNIN";
var NotifyClient =
require("notifications-node-client").NotifyClient;
const notifyClient = new NotifyClient(
process.env.NOTIFY_API_KEY
);
await notifyClient
.sendEmail(
locale == "cy" ? templateIdcy : templateId,
emailAddress,
{
personalisation: personalisation,
reference: reference,
// emailReplyToId: emailReplyToId,
}
)
//.then((response) => console.log(response))
.catch((err) => consoleLogger(err));
},
}),
],
adapter: PrismaAdapter(prisma),
secret: process.env.SECRET,
session: {
jwt: true,
pages: {},
theme: "dark",
debug: true,
},
},
});
cookies: {
callbackUrl: {
name: `__Secure-next-auth.callback-url`,
options: {
sameSite: "lax",
path: "/",
secure: true,
},
},
},
pages: {
signIn: (locale == "cy" ? "/cy" : "") + "/auth/signin",
//signOut: "/logout/signout",
error: (locale == "cy" ? "/cy" : "") + "/auth/error", // Error code passed in query string as ?error=
verifyRequest:
(locale == "cy" ? "/cy" : "") + "/auth/verify-request", // (used for check email message)
newUser: locale + "/account/register", // New users will be directed here on first sign in (leave the property out if not of interest)
},
callbacks: {
session: async (session, user) => {
//console.log(user);
return Promise.resolve(session);
},
async redirect({ url, baseUrl }) {
// // Allows relative callback URLs
// if (url.startsWith("/")) return `${baseUrl}${url}`;
// // Allows callback URLs on the same origin
// else if (new URL(url).origin === baseUrl) return url;
let newURL =
locale == "cy"
? process.env.CY_API_ROOT
: process.env.NEXTAUTH_URL;
console.log("baseurl:", newURL);
//return baseUrl;
return newURL;
},
},
};
};
export default (req, res) => {
//console.log("----------", authOptions(req.cookies["pedw_locale"]));
//console.log("----------",
return NextAuth(req, res, authOptions(req.cookies["pedw_locale"], req));
};
+5 -1
View File
@@ -49,7 +49,11 @@ export default async function ApiProxy(req, res) {
searchString +
"')) and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true";
//console.log("basic search ", queryUrl);
console.log(
"basic search ",
queryUrl,
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl)
);
var apiResponse = _.isEmpty(req.query)
? res.status(400).json()
@@ -48,7 +48,7 @@ export default async function ApiProxy(req, res) {
var caseReference = req.query.caseReference.split("'").join("''");
var token = await getToken();
console.log("the case:", req.query, caseReference);
//console.log("the case:", req.query, caseReference);
var queryUrl =
appealType +
+1 -1
View File
@@ -27,7 +27,7 @@ ApiProxy.get(async (req, res) => {
if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) {
const blobObj = await getProgressBlobs(containerName, casefolderID)
.then((data) => {
console.log("Progress blob path:", data.path);
//console.log("Progress blob path:", data.path);
return downloadProgressFile(
containerName,
data.path,
+41 -3
View File
@@ -6,10 +6,20 @@ import Footer from "../../components/footer";
import Header from "../../components/header";
import Breadcrumbs from "../../components/breadcrumbs";
import { getCsrfToken } from "next-auth/react";
import { parseCookies, setCookie, destroyCookie } from "nookies";
import { ca } from "date-fns/locale";
const SignIn = (props) => {
let { t, lang } = useTranslation();
const { footerLinks, pages, csrfToken } = props;
const { footerLinks, pages, csrfToken, callbackUrl } = props;
let formURL =
new URL(window.location.href).protocol +
"//" +
new URL(window.location.href).hostname +
":" +
new URL(window.location.href).port +
"/api/auth/signin/email";
return (
<div>
@@ -33,7 +43,7 @@ const SignIn = (props) => {
<div className="govuk-grid-column-two-thirds ">
<form
method="post"
action="/api/auth/signin/email"
action={"/api/auth/signin/email"}
>
<div className="govuk-form-group">
<input
@@ -42,6 +52,12 @@ const SignIn = (props) => {
type="hidden"
defaultValue={csrfToken}
/>
<input
className="govuk-input"
name="callbackUrl"
type="hidden"
defaultValue={callbackUrl}
/>
<label
className="govuk-label"
htmlFor="email"
@@ -75,9 +91,31 @@ const SignIn = (props) => {
};
export async function getServerSideProps(context) {
console.log("-1-1-1-1-", context.query.callbackUrl, context.locale);
console.log("------ " + context.query.callbackUrl);
// setCookie(context, "next-auth.callback-url", context.query.callbackUrl, {
// path: "/",
// });
const csrfToken = await getCsrfToken(context);
let callback =
context.locale != "cy"
? process.env.NEXTAUTH_URL
: "https://" + process.env.I18N_DOMAIN + ":3000";
context.query.callbackUrl = callback;
let formURL =
new URL(callback).protocol +
"//" +
new URL(callback).hostname +
":" +
new URL(callback).port; // +
// "/api/auth/signin/email";
console.log("******", formURL, callback, csrfToken);
return {
props: { csrfToken },
props: { csrfToken: csrfToken, callbackUrl: formURL, redirect: true },
};
}
+1 -1
View File
@@ -56,7 +56,7 @@ const SignIn = (props) => {
export async function getServerSideProps(context) {
const csrfToken = await getCsrfToken(context);
return {
props: { csrfToken },
props: { csrfToken, locale: context.locale },
};
}
+10 -1
View File
@@ -43,7 +43,16 @@ function Error({ statusCode }, props) {
className="govuk-link"
onClick={() => {
window.localStorage.clear(),
destroyCookie({}, "pinsUser"),
destroyCookie(
null,
"next-auth.csrf-token"
),
destroyCookie(
null,
"next-auth.callback-url"
),
destroyCookie(null, "pedw_locale"),
destroyCookie(null, "pinsUser"),
session != null
? signOut({
callbackUrl: "/",
+3 -1
View File
@@ -28,6 +28,7 @@ const Home = (props) => {
loginEmailStr,
loggedInUserEmail,
hasLoginCode,
siteurl,
} = props;
let { t, lang } = useTranslation();
@@ -60,7 +61,6 @@ const Home = (props) => {
})
: (setCookie(null, "pinsUser", loggedInUserId.value[0].contactid, {
path: "/",
expires: expDate,
}),
router.replace({
pathname:
@@ -137,6 +137,7 @@ const Home = (props) => {
showLogin={showLogin}
showMap={showMap}
loggedInUserId={loggedInUserId}
siteurl={siteurl}
/>
</>
)}
@@ -195,6 +196,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
loggedInUserId: portalUserObj,
loggedInUserEmail: loginEmailStr,
hasLoginCode: hasLoginCode,
siteurl: process.env.API_ROOT,
},
};
}
+3 -1
View File
@@ -91,7 +91,9 @@ const LogOut = (props) => {
<div className="govuk-width-container">
<h2>{t("common:logged-out-title")}</h2>
<div className="govuk-!-margin-top-9 govuk-!-margin-bottom-9">
<Link href="/">{t("common:logged-out-link")}</Link>
<Link href={locale == "cy" ? "/cy" : "/"}>
{t("common:logged-out-link")}
</Link>
</div>
</div>
<Footer footerLinks={footerLinks} />
+3 -1
View File
@@ -217,7 +217,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
const { cookies } = req;
//console.log(cookies);
//console.log("the query", query.appealtypes);
console.log("the query", query);
let loggedInUser = cookies.pinsUser;
let thisSession = await getSession(ctx);
@@ -228,6 +228,8 @@ export const getServerSideProps = wrapper.getServerSideProps(
//console.log("logged ident:", loggedInUserIdent);
console.log("which appeal: ", query.appealtypes);
const [appealTypeData, mandatoryFieldsData, pickListData, blobList] =
await Promise.all([
await getAppealsTypesForNewAppeal(),
+62 -12
View File
@@ -263,13 +263,33 @@ const getDetails = (resultsObj, detailsType) => {
resultsObj = resultsObj.value;
if (detailsType == "myRepresentations") {
const repsObj = resultsObj.map((searchDetail, index) => {
console.log("==== ", searchDetail["_pinswg_case_value"]);
detailsArr.push(
getCase(searchDetail["incidentID"]).then((data) => {
let caseID = "";
switch (detailsType) {
case "myCases":
caseID = data.pinswg_title;
break;
case "myWatchedCases":
caseID =
data[
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
];
break;
case "awaitingSubmission":
caseID = data.ticketnumber;
break;
case "myRepresentations":
caseID = data.casereference;
break;
default:
caseID = data.pinswg_title;
}
return getPortalModuleDetails(
getFormCollectionByID(data.pinswg_appealcasetype)
.LogicalCollectionName,
data.ticketnumber
caseID
);
})
);
@@ -277,24 +297,54 @@ const getDetails = (resultsObj, detailsType) => {
}
const detailsObj = resultsObj.map((searchDetail, index) => {
let caseID = "";
switch (detailsType) {
case "myCases":
caseID = searchDetail.pinswg_title;
break;
case "myWatchedCases":
caseID =
searchDetail[
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
];
break;
case "awaitingSubmission":
caseID = searchDetail.ticketnumber;
break;
case "myRepresentations":
caseID = searchDetail.casereference;
break;
default:
caseID = searchDetail.pinswg_title;
}
//console.log(detailsType, " case id : ", caseID);
if (searchDetail.pinswg_appealcasetype == null) {
console.log(
detailsType != "myWatchedCases"
? searchDetail.ticketnumber
: searchDetail[
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
]
"detailsObj:",
detailsType,
detailsType == "myCases" && searchDetail.pinswg_title,
detailsType == "myWatchedCases" &&
searchDetail[
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
],
detailsType == "awaitingSubmission" &&
searchDetail.ticketnumber,
detailsType == "myRepresentations" && searchDetail.casereference
);
} else {
detailsArr.push(
getPortalModuleDetails(
getFormCollectionByID(searchDetail.pinswg_appealcasetype)
.LogicalCollectionName,
detailsType != "myWatchedCases"
? searchDetail.ticketnumber
: searchDetail[
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
]
caseID
// detailsType != "myWatchedCases"
// ? searchDetail.ticketnumber
// : searchDetail[
// "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
// ]
)
);
}