ENCOA-126: Corporate should not be allowed to edit is own name
This commit is contained in:
@@ -12,7 +12,7 @@ import Link from "next/link";
|
||||
import axios from "axios";
|
||||
import {ErrorMessage} from "@/constants/errors";
|
||||
import clsx from "clsx";
|
||||
import {CorporateUser, EmploymentStatus, EMPLOYMENT_STATUS, Gender, User, DemographicInformation} from "@/interfaces/user";
|
||||
import {CorporateUser, EmploymentStatus, EMPLOYMENT_STATUS, Gender, User, DemographicInformation, MasterCorporateUser} from "@/interfaces/user";
|
||||
import CountrySelect from "@/components/Low/CountrySelect";
|
||||
import {shouldRedirectHome} from "@/utils/navigation.disabled";
|
||||
import moment from "moment";
|
||||
@@ -34,8 +34,10 @@ import {capitalize} from "lodash";
|
||||
import TopicModal from "@/components/Medium/TopicModal";
|
||||
import {v4} from "uuid";
|
||||
import {checkAccess, getTypesOfUser} from "@/utils/permissions";
|
||||
import {getUserCorporate} from "@/utils/groups.be";
|
||||
import {InferGetServerSidePropsType} from "next";
|
||||
|
||||
export const getServerSideProps = withIronSessionSsr(({req, res}) => {
|
||||
export const getServerSideProps = withIronSessionSsr(async ({req, res}) => {
|
||||
const user = req.session.user;
|
||||
|
||||
if (!user || !user.isVerified) {
|
||||
@@ -57,18 +59,19 @@ export const getServerSideProps = withIronSessionSsr(({req, res}) => {
|
||||
}
|
||||
|
||||
return {
|
||||
props: {user: req.session.user},
|
||||
props: {user, linkedCorporate: await getUserCorporate(user.id)},
|
||||
};
|
||||
}, sessionOptions);
|
||||
|
||||
interface Props {
|
||||
user: User;
|
||||
mutateUser: Function;
|
||||
linkedCorporate?: CorporateUser | MasterCorporateUser;
|
||||
}
|
||||
|
||||
const DoubleColumnRow = ({children}: {children: ReactNode}) => <div className="flex flex-col lg:flex-row gap-8 w-full">{children}</div>;
|
||||
|
||||
function UserProfile({user, mutateUser}: Props) {
|
||||
function UserProfile({user, mutateUser, linkedCorporate}: Props) {
|
||||
const [bio, setBio] = useState(user.bio || "");
|
||||
const [name, setName] = useState(user.name || "");
|
||||
const [email, setEmail] = useState(user.email || "");
|
||||
@@ -245,7 +248,7 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
<h1 className="text-4xl font-bold mb-6 -md:hidden">Edit Profile</h1>
|
||||
<form className="flex flex-col items-center gap-6 w-full" onSubmit={(e) => e.preventDefault()}>
|
||||
<DoubleColumnRow>
|
||||
{user.type !== "corporate" ? (
|
||||
{user.type !== "corporate" && user.type !== "mastercorporate" ? (
|
||||
<Input
|
||||
label={user.type === "agent" ? "English name" : "Name"}
|
||||
type="text"
|
||||
@@ -260,6 +263,7 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
label="Company name"
|
||||
type="text"
|
||||
name="name"
|
||||
disabled={!!linkedCorporate}
|
||||
onChange={(e) =>
|
||||
setCorporateInformation((prev) => ({
|
||||
...prev!,
|
||||
@@ -502,6 +506,7 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
label="Department"
|
||||
placeholder="CEO, Head of Marketing..."
|
||||
required
|
||||
disabled={!!linkedCorporate}
|
||||
/>
|
||||
</DoubleColumnRow>
|
||||
</>
|
||||
@@ -638,7 +643,7 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
);
|
||||
}
|
||||
|
||||
export default function Home() {
|
||||
export default function Home({linkedCorporate}: {linkedCorporate?: CorporateUser | MasterCorporateUser}) {
|
||||
const {user, mutateUser} = useUser({redirectTo: "/login"});
|
||||
|
||||
return (
|
||||
@@ -653,7 +658,7 @@ export default function Home() {
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
</Head>
|
||||
<ToastContainer />
|
||||
{user && <UserProfile user={user} mutateUser={mutateUser} />}
|
||||
{user && <UserProfile linkedCorporate={linkedCorporate} user={user} mutateUser={mutateUser} />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user