c.currency === currency)?.label}`}
+ value={`${(commission! / 100) * price!} ${CURRENCIES.find((c) => c.currency === currency)?.label}`}
onChange={() => null}
type="text"
defaultValue={0}
diff --git a/src/pages/profile.tsx b/src/pages/profile.tsx
index 3d142ed4..0c0ed4cc 100644
--- a/src/pages/profile.tsx
+++ b/src/pages/profile.tsx
@@ -50,27 +50,32 @@ export const getServerSideProps = withIronSessionSsr(({req, res}) => {
};
}, sessionOptions);
-export default function Home() {
- const [bio, setBio] = useState("");
- const [name, setName] = useState("");
- const [email, setEmail] = useState("");
+interface Props {
+ user: User;
+ mutateUser: Function,
+}
+
+function UserProfile({
+ user,
+ mutateUser,
+}: Props) {
+ const [bio, setBio] = useState(user.bio || '');
+ const [name, setName] = useState(user.name || '');
+ const [email, setEmail] = useState(user.email || '');
const [password, setPassword] = useState("");
const [newPassword, setNewPassword] = useState("");
const [isLoading, setIsLoading] = useState(false);
- const [profilePicture, setProfilePicture] = useState("");
+ const [profilePicture, setProfilePicture] = useState(user.profilePicture);
- const [country, setCountry] = useState
();
- const [phone, setPhone] = useState();
- const [gender, setGender] = useState();
- const [employment, setEmployment] = useState();
- const [position, setPosition] = useState();
- const [companyName, setCompanyName] = useState("");
- const [commercialRegistration, setCommercialRegistration] = useState("");
+ const [country, setCountry] = useState(user.demographicInformation?.country || '');
+ const [phone, setPhone] = useState(user.demographicInformation?.phone || '');
+ const [gender, setGender] = useState(user.demographicInformation?.gender || undefined);
+ const [employment, setEmployment] = useState(user.type === "corporate" ? undefined : user.demographicInformation?.employment);
+ const [position, setPosition] = useState(user.type === "corporate" ? user.demographicInformation?.position : undefined);
+ const [companyName, setCompanyName] = useState(user.type === 'agent' ? user.agentInformation?.companyName : undefined);
+ const [commercialRegistration, setCommercialRegistration] = useState(user.type === 'agent' ? user.agentInformation?.commercialRegistration : undefined);
const profilePictureInput = useRef(null);
-
- const {user, mutateUser} = useUser({redirectTo: "/login"});
-
const expirationDateColor = (date: Date) => {
const momentDate = moment(date);
const today = moment(new Date());
@@ -80,24 +85,6 @@ export default function Home() {
if (today.add(7, "days").isAfter(momentDate)) return "!bg-mti-orange-ultralight border-mti-orange-light";
};
- useEffect(() => {
- if (user) {
- setName(user.name);
- setEmail(user.email);
- setBio(user.bio);
- setProfilePicture(user.profilePicture);
- setCountry(user.demographicInformation?.country);
- setPhone(user.demographicInformation?.phone);
- setGender(user.demographicInformation?.gender);
- setEmployment(user.type === "corporate" ? undefined : user.demographicInformation?.employment);
- setPosition(user.type === "corporate" ? user.demographicInformation?.position : undefined);
- if(user.type === 'agent') {
- setCompanyName(user.agentInformation?.companyName)
- setCommercialRegistration(user.agentInformation?.commercialRegistration)
- }
- }
- }, [user]);
-
const convertBase64 = (file: File) => {
return new Promise((resolve, reject) => {
const fileReader = new FileReader();
@@ -159,6 +146,258 @@ export default function Home() {
setIsLoading(false);
};
+ return (
+
+
+ Edit Profile
+
+
+
+
(profilePictureInput.current as any)?.click()}>
+
+
+
+
+

+
+
+
(profilePictureInput.current as any)?.click()}
+ className="cursor-pointer text-mti-purple-light text-sm">
+ Change picture
+
+
{USER_TYPE_LABELS[user.type]}
+
+ {user.type === 'agent' && (
+
+
}.png`})
+
+ )}
+
+
+
+ Bio
+
+
+
+
+
+
+
+
+
+
+ );
+}
+
+
+export default function Home() {
+ const {user, mutateUser } = useUser({redirectTo: "/login"});
+
return (
<>
@@ -171,252 +410,9 @@ export default function Home() {
- {user && (
-
-
- Edit Profile
-
-
-
-
(profilePictureInput.current as any)?.click()}>
-
-
-
-
-

-
-
-
(profilePictureInput.current as any)?.click()}
- className="cursor-pointer text-mti-purple-light text-sm">
- Change picture
-
-
{USER_TYPE_LABELS[user.type]}
-
- {user.type === 'agent' && (
-
-
}.png`})
-
- )}
-
-
-
- Bio
-
-
-
-
-
-
-
-
-
-
- )}
+ {user && }
>
);
-}
+
+
+}
\ No newline at end of file
diff --git a/src/resources/user.ts b/src/resources/user.ts
index 340123bc..ffc2c8b5 100644
--- a/src/resources/user.ts
+++ b/src/resources/user.ts
@@ -1,4 +1,4 @@
-import {Type} from "@/interfaces/user";
+import {Type, User, CorporateUser} from "@/interfaces/user";
export const USER_TYPE_LABELS: {[key in Type]: string} = {
student: "Student",
@@ -8,3 +8,7 @@ export const USER_TYPE_LABELS: {[key in Type]: string} = {
admin: "Admin",
developer: "Developer",
};
+
+export function isCorporateUser(user: User): user is CorporateUser {
+ return (user as CorporateUser).corporateInformation !== undefined;
+ }
\ No newline at end of file