Skip to content

Commit

Permalink
refactor frontend file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
HuzzNZ committed Jun 1, 2024
1 parent a5edea2 commit 6b37393
Show file tree
Hide file tree
Showing 78 changed files with 268 additions and 261 deletions.
3 changes: 2 additions & 1 deletion cypress/e2e/consts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PUBLIC_FRONT_END_PAGES, ROUTES } from "@/../../frontend/app/lib/consts"
import Page from "../../frontend/app/type/PageType"

import Page from "../../frontend/app/lib/types";

let uiUri

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/publicFrontend/flowerNav.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PUBLIC_FRONTEND_URLS } from "../consts"
import Page from "../../../frontend/app/type/PageType"
import { compareSnapshots } from "cypress-visual-regression/dist/plugin"
import { Page } from "../../../frontend/app/lib/types"

const getTransformRotationAngle = (cssTransformMatrix, absoluteValue) => {
const cssTransformMatrixIndexes = cssTransformMatrix.split("(")[1].split(")")[0].split(",")
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/(auth)/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import AuthDashboard from "@/app/(auth)/components/AuthDashboard"
import AuthLayout from "@/app/(auth)/components/AuthLayout"
import AuthProvider from "@/app/(auth)/components/AuthProvider"
import LoginForm from "@/app/(auth)/components/LoginForm"
import ChangePasswordForm from "@/app/(auth)/components/ChangePasswordForm"
import LoginForm from "@/app/(auth)/components/forms/LoginForm"
import ChangePasswordForm from "@/app/(auth)/components/forms/ChangePasswordForm"
import UserScopeLabel from "@/app/(auth)/components/UserScopeLabel"

export { AuthDashboard, AuthLayout, AuthProvider, LoginForm, ChangePasswordForm, UserScopeLabel }
4 changes: 2 additions & 2 deletions frontend/app/(auth)/forgot-password/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use client"

import { useState } from "react"
import ForgotPasswordForm from "../components/ForgotPasswordForm"
import ResetPasswordForm from "../components/ResetPasswordForm"
import ForgotPasswordForm from "../components/forms/ForgotPasswordForm"
import ResetPasswordForm from "../components/forms/ResetPasswordForm"

export default function ForgotPasswordPage() {
const [emailToResetPasswordFor, setEmailToResetPasswordFor] = useState<null | string>(null)
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/(auth)/signup/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react"
import SignupForm from "@/app/(auth)/components/SignupForm"
import SignupForm from "@/app/(auth)/components/forms/SignupForm"

export default function Signup() {
return (
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/(cms)/(articles)/news/[id]/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from "react"
import { ArticleType } from "@aapc/types"
import { notFound } from "next/navigation"
import { getNewsById } from "@/app/services/news"
import ArticleForm from "@/app/(cms)/(articles)/components/ArticleForm"
import ExternalArticleForm from "@/app/(cms)/(articles)/components/ExternalArticleForm"
import ArticleForm from "@/app/(cms)/(articles)/components/forms/ArticleForm"
import ExternalArticleForm from "@/app/(cms)/(articles)/components/forms/ExternalArticleForm"
import { Metadata } from "next"
import { getMetadata } from "@/app/lib/util"
import ArticleCard from "@/app/(content)/(articles)/components/ArticleCard";
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/(cms)/(articles)/news/publish/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { Article, ArticleType } from "@aapc/types"
import { Nullable } from "@/app/lib/types"
import icons from "@/app/lib/icons"
import Button from "@/app/components/Button"
import ExternalArticleForm from "@/app/(cms)/(articles)/components/ExternalArticleForm"
import ArticleForm from "@/app/(cms)/(articles)/components/ArticleForm"
import ExternalArticleForm from "@/app/(cms)/(articles)/components/forms/ExternalArticleForm"
import ArticleForm from "@/app/(cms)/(articles)/components/forms/ArticleForm"

export default function CreateNewsPage() {
const [exampleArticle, setExampleArticle] = useState<Nullable<Article>>(null)
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/(cms)/(articles)/research/[id]/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import React from "react"
import { ArticleType } from "@aapc/types"
import { notFound } from "next/navigation"
import { getResearchById } from "@/app/services/research"
import ArticleForm from "@/app/(cms)/(articles)/components/ArticleForm"
import ArticleForm from "@/app/(cms)/(articles)/components/forms/ArticleForm"
import { Metadata } from "next"
import { getMetadata } from "@/app/lib/util"
import ExternalArticleForm from "../../../components/ExternalArticleForm"
import ExternalArticleForm from "../../../components/forms/ExternalArticleForm"
import ArticleCard from "@/app/(content)/(articles)/components/ArticleCard";

export const metadata: Metadata = getMetadata("Edit Research")
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/(cms)/(articles)/research/publish/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { Article, ArticleType } from "@aapc/types"
import { Nullable } from "@/app/lib/types"
import icons from "@/app/lib/icons"
import Button from "@/app/components/Button"
import ExternalArticleForm from "@/app/(cms)/(articles)/components/ExternalArticleForm"
import ArticleForm from "@/app/(cms)/(articles)/components/ArticleForm"
import ExternalArticleForm from "@/app/(cms)/(articles)/components/forms/ExternalArticleForm"
import ArticleForm from "@/app/(cms)/(articles)/components/forms/ArticleForm"

export default function CreateResearchPage() {
const [exampleArticle, setExampleArticle] = useState<Nullable<Article>>(null)
Expand Down
6 changes: 3 additions & 3 deletions frontend/app/(cms)/pollen/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import React, { useEffect, useState, useRef } from "react"
import { PollenData } from "@aapc/types"
import { parseSpreadsheet } from "./util/parseExcel"
import { parseSpreadsheet } from "@/app/lib/pollenData/parseExcel"
import parseAssumptions from "@/app/lib/pollenData/parseAssumptions"
import PollenCalendar from "@/app/components/PollenCalendar"
import parseAssumptions from "./util/parseAssumptions"
import { createPollenData } from "@/app/services/pollen"
import { useAuth } from "@/app/lib/hooks"
import Button from "@/app/components/Button"
import icons from "@/app/lib/icons";
import icons from "@/app/lib/icons"
import ButtonLink from "@/app/components/ButtonLink"

type ParseError = {
Expand Down
24 changes: 12 additions & 12 deletions frontend/app/(content)/about/page.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import React from "react"
import Image from "next/image"

import amy from "./images/researchers/amy.jpeg"
import katherine from "./images/researchers/katherine.jpeg"
import stuti from "./images/researchers/stuti.jpeg"
import stutiHeaderImage from "./images/researchers/stutiHeaderImage.jpg"
import katherineHeaderImage from "./images/researchers/katHeaderImage.jpg"
import amyHeaderImage from "./images/researchers/amyHeaderImage.jpeg"
import amy from "@/app/public/researchers/amy.jpeg"
import katherine from "@/app/public/researchers/katherine.jpeg"
import stuti from "@/app/public/researchers/stuti.jpeg"
import stutiHeaderImage from "@/app/public/researchers/stutiHeaderImage.jpg"
import katherineHeaderImage from "@/app/public/researchers/katHeaderImage.jpg"
import amyHeaderImage from "@/app/public/researchers/amyHeaderImage.jpeg"

import teamPicture from "./images/Team AWMM roof.jpeg"
import teamPicture from "../../public/Team AWMM roof.jpeg"

import aucklandMuseumLogo from "./images/organisations/aucklandMuseum.png"
import allergyNZLogo from "./images/organisations/allergyNZ.png"
import masseyLogo from "./images/organisations/masseyUniversity.png"
import victoriaLogo from "./images/organisations/victoriaUniversityOfWellington.png"
import uoaLogo from "./images/organisations/universityOfAuckland.png"
import aucklandMuseumLogo from "@/app/public/organisations/aucklandMuseum.png"
import allergyNZLogo from "@/app/public/organisations/allergyNZ.png"
import masseyLogo from "@/app/public/organisations/masseyUniversity.png"
import victoriaLogo from "@/app/public/organisations/victoriaUniversityOfWellington.png"
import uoaLogo from "@/app/public/organisations/universityOfAuckland.png"

import { FaTwitter } from "react-icons/fa"
import Link from "next/link"
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/(content)/contact/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import Image from "next/image";
import ContactForm from "@/app/components/ContactForm";
import pollenImg from "@/app/public/pollenimg.svg";
import pollenImg from "@/app/public/homepage/pollenimg.svg";
import { DEFAULT_MAILTO_ADDRESS } from "@/app/lib/consts";

export default function Contact() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LearnMoreLink } from "@/app/components/SourceLink"
import Image from "next/image"
import ArtificialTearsExplanationImage from "./images/artificialTears.png"
import ArtificialTearsExplanationImage from "../../../public/health/artificialTears.png"

/* eslint-disable react/no-unescaped-entities */
export default function ArtificialTearsExplanation() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use client"

import { useState } from "react"
import HumanCartoon from "./images/humanCartoon.svg"
import HumanCartoon from "../../../public/health/humanCartoon.svg"
import Image from "next/image"
import commonSymptoms from "./commonSymptoms"
import commonSymptoms from "@/app/(content)/health/content/commonSymptoms"
import ExplanationDialog from "./ExplanationDialog"

export default function InteractiveBodyDiagram() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import WashingMachineImage from "./images/washingMachine.svg"
import DustFurniture from "./images/dustFurniture.svg"
import NasalRinseImage from "./images/rinseNasalPassages.svg"
import WashHandsImage from "./images/washHands.svg"
import ShutWindowsImages from "./images/shutWindows.svg"
import AvoidSmokingImage from "./images/avoidSmoking.svg"
import NasalRinseExplanation from "./explanations/NasalRinse"
import RedEyeImage from "./images/redeye.svg"
import ArtificialTearsExplanation from "./explanations/ArtificialTears"
import WashingMachineImage from "../../../public/health/washingMachine.svg"
import DustFurniture from "../../../public/health/dustFurniture.svg"
import NasalRinseImage from "../../../public/health/rinseNasalPassages.svg"
import WashHandsImage from "../../../public/health/washHands.svg"
import ShutWindowsImages from "../../../public/health/shutWindows.svg"
import AvoidSmokingImage from "../../../public/health/avoidSmoking.svg"
import NasalRinseExplanation from "@/app/(content)/health/components/NasalRinse"
import RedEyeImage from "../../../public/health/redeye.svg"
import ArtificialTearsExplanation from "@/app/(content)/health/components/ArtificialTears"

const strategies = {
"Wash bedding regularly": {
Expand Down
8 changes: 4 additions & 4 deletions frontend/app/(content)/health/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import React, { useState } from "react"
import PageTemplate from "@/app/components/PageContentTemplate"

import StrategyCard from "./components/commonStrategies/StrategyCard"
import InteractiveBodyDiagram from "./InteractiveBodyDiagram"
import StrategyCard from "@/app/(content)/health/components/StrategyCard"
import InteractiveBodyDiagram from "./components/InteractiveBodyDiagram"
import SourceLink, { LearnMoreLink } from "@/app/components/SourceLink"
import strategies from "./components/commonStrategies/commonStrategies"
import ExplanationDialog from "./ExplanationDialog"
import strategies from "@/app/(content)/health/content/commonStrategies"
import ExplanationDialog from "./components/ExplanationDialog"

export default function HealthPage() {
const [selectedTechnique, selectTechnique] = useState<null | string>(null)
Expand Down
139 changes: 139 additions & 0 deletions frontend/app/(content)/manage-users/components/EditUserRoleModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import { IUser, UserScope } from "@aapc/types"
import React, { Dispatch, ForwardedRef, forwardRef, SetStateAction, useState } from "react"
import useModal, { ModalRef } from "@/app/lib/hooks/useModal"
import { useAuth } from "@/app/lib/hooks"
import { Nullable } from "@/app/lib/types"
import { editUserScope } from "@/app/services/user"
import Modal from "@/app/components/modals/components/Modal"
import Select from "react-select"
import Button from "@/app/components/Button"
import icons from "@/app/lib/icons"

type UserRoleOption = {
value: UserScope[]
label: string
}

type EditUserRoleModalProps = {
user: IUser,
setUser: Dispatch<SetStateAction<IUser>>
}

const EditUserRoleModal = forwardRef(
function EditUserRoleModal({ user, setUser }: EditUserRoleModalProps, ref: ForwardedRef<ModalRef>) {
const { token } = useAuth()
const [hidden, setHidden] = useModal(`${user.username}-edit-role`, ref)
const [selectedRole, setSelectedRole] = useState<Nullable<UserRoleOption>>(null)
const [pending, setPending] = useState(false)
const [success, setSuccess] = useState(false)
const [error, setError] = useState<Nullable<string>>(null)

const roles: UserRoleOption[] = [
{
value: [UserScope.user, UserScope.regular],
label: "Regular User"
},
{
value: [UserScope.user, UserScope.regular, UserScope.premium],
label: "Premium User"
},
{
value: [UserScope.user, UserScope.regular, UserScope.premium, UserScope.maintainer],
label: "Site Maintainer"
},
{
value: [UserScope.user, UserScope.regular, UserScope.premium, UserScope.maintainer, UserScope.admin],
label: "Site Admin"
},
]

const handleEdit = () => {
setSuccess(false)
setError(null)
if (!selectedRole) return
setPending(true)
editUserScope(user.username, selectedRole.value, { token }).then(r => {
if (r.success) {
setPending(false)
setSuccess(true)
setUser && setUser(r.result)
} else {
setPending(false)
setError(r.message)
}
})
}

let currentOption = roles[0]
if (user.scopes.includes(UserScope.admin)) {
currentOption = roles[3]
} else if (user.scopes.includes(UserScope.maintainer)) {
currentOption = roles[2]
} else if (user.scopes.includes(UserScope.premium)) {
currentOption = roles[1]
}
return (
<Modal modalId={`${user.username}-edit-role`} hidden={hidden}
innerClassName={`flex flex-row gap-x-3 justify-between bg-white`}>
<div className={"grow min-h-72 flex flex-col justify-between"}>
<div>
<p className={"form-label"}>Editing @{user.username}&apos;s role</p>
<Select
options={roles}
isSearchable={true}
className={"min-w-44"}
defaultValue={currentOption}
onChange={e => {
setSelectedRole(e)
}}
/>
<div className={"my-6"}>
<p className={"smallest text-slate-800 mt-4"}>
If you wish to give access for a user to manage site content, grant them the <b
className={"font-semibold"}>Site Maintainer</b> role.
</p>
<p className={"smallest text-red-500 mt-4"}>
Granting other users the <b className={"font-semibold"}>Site Admin</b> role also grants
them the permission to <b className={"font-semibold"}>remove that role from you</b>!
</p>
<p className={"smallest text-red-500 mt-4 font-semibold"}>
Only grant the Site Admin role to users you trust.
</p>
</div>
</div>
<div>
{success &&
<p className={"form-success mb-2"}>Successfully edited user scope.</p>
}
{error &&
<p className={"form-error mb-2"}>{error}</p>
}
<div className={"flex flex-row gap-x-4"}>
<Button
theme={"secondary"}
icon={icons.back}
text={"Back"}
onClick={() => setHidden(true)}
leftIcon
/>
<Button
theme={"green"}
disabled={pending}
icon={icons.edit}
text={pending ? "Editing..." : "Edit"}
onClick={handleEdit}
/>
</div>
</div>
</div>
<Button
theme={"secondary"}
icon={icons.close}
onClick={() => setHidden(true)}
/>
</Modal>
)
}
)

export default EditUserRoleModal
Loading

0 comments on commit 6b37393

Please sign in to comment.