-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(profile): Add other user's profile detail in appointment (#722)
- Loading branch information
Showing
11 changed files
with
235 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright [2023] [Privacypal Authors] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { OtherUserProfileDetails } from "@components/profile/OtherUserProfileDetails"; | ||
import React from "react"; | ||
import { auth } from "src/auth"; | ||
import { Metadata } from "next"; | ||
|
||
export const metadata: Metadata = { | ||
title: "Other User Profile Detail", | ||
}; | ||
|
||
export default async function OtherUserProfilePage({ | ||
params, | ||
}: { | ||
params: { withUser: string }; | ||
}) { | ||
const session = await auth(); | ||
if (!session) { | ||
return <main>Not logged in</main>; | ||
} | ||
return ( | ||
<main> | ||
<OtherUserProfileDetails withUser={params.withUser} user={session.user} /> | ||
</main> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
app/web/src/components/profile/OtherUserProfileDetails.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/* | ||
* Copyright [2023] [Privacypal Authors] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
"use client"; | ||
import React, { useEffect, useState } from "react"; | ||
import { | ||
Card, | ||
CardTitle, | ||
CardBody, | ||
CardHeader, | ||
Flex, | ||
Title, | ||
FlexItem, | ||
Divider, | ||
CardFooter, | ||
Alert, | ||
} from "@patternfly/react-core"; | ||
import { User } from "next-auth"; | ||
import { UserRole } from "@lib/userRole"; | ||
import { CognitoUser } from "@lib/cognito"; | ||
import { getUserByUsername } from "@app/actions"; | ||
import { CSS } from "@lib/utils"; | ||
|
||
const cardContainer: CSS = { | ||
display: "flex", | ||
justifyContent: "center", | ||
filter: "drop-shadow(0px 4px 4px rgba(0, 0, 0, 0.25))", | ||
}; | ||
|
||
const cardStyle: CSS = { | ||
width: "25%", | ||
}; | ||
|
||
interface ProfileDetailsProps { | ||
user: User; | ||
withUser: string; | ||
} | ||
|
||
export const OtherUserProfileDetails = ({ | ||
user, | ||
withUser, | ||
}: ProfileDetailsProps) => { | ||
const [userDetails, setUserDetails] = useState<CognitoUser | null>(null); | ||
const [loading, setLoading] = useState(true); | ||
const [error, setError] = useState<string | null>(null); | ||
|
||
useEffect(() => { | ||
const fetchUserDetails = async () => { | ||
try { | ||
const user = await getUserByUsername(withUser); | ||
if (user) { | ||
setUserDetails(user); | ||
setLoading(false); | ||
} else { | ||
setLoading(false); | ||
setError("User details not found"); | ||
} | ||
} catch (error) { | ||
console.error("Error fetching user details:", error); | ||
setLoading(false); | ||
setError("Error fetching user details"); | ||
} | ||
}; | ||
|
||
fetchUserDetails(); | ||
}, [withUser]); | ||
|
||
if (loading) { | ||
return <div>Loading...</div>; | ||
} | ||
|
||
if (error) { | ||
return ( | ||
<Alert variant="danger" title={error} style={{ marginTop: "1rem" }} /> | ||
); | ||
} | ||
|
||
if (!userDetails) { | ||
return ( | ||
<Alert | ||
variant="danger" | ||
title="User details not found." | ||
style={{ marginTop: "1rem" }} | ||
/> | ||
); | ||
} | ||
|
||
const withUserRole = | ||
user.role === UserRole.PROFESSIONAL | ||
? UserRole.CLIENT | ||
: UserRole.PROFESSIONAL; | ||
|
||
return ( | ||
<div style={cardContainer}> | ||
<Card aria-label="Personal Information" style={cardStyle}> | ||
<CardHeader style={{ textAlign: "center", marginBottom: "0.5rem" }}> | ||
<CardTitle | ||
component="h2" | ||
style={{ fontSize: "2rem", fontWeight: "bold", margin: 0 }} | ||
> | ||
Professional's Information | ||
</CardTitle> | ||
</CardHeader> | ||
|
||
<CardBody> | ||
<Divider /> | ||
<Flex | ||
direction={{ default: "row" }} | ||
alignItems={{ default: "alignItemsFlexStart" }} | ||
justifyContent={{ default: "justifyContentSpaceBetween" }} | ||
grow={{ default: "grow" }} | ||
> | ||
<FlexItem> | ||
<Flex direction={{ default: "column" }}> | ||
<FlexItem> | ||
<Title headingLevel="h2">Username:</Title> | ||
<span>{userDetails.username}</span> | ||
</FlexItem> | ||
|
||
<FlexItem> | ||
<Title headingLevel="h2">Email:</Title> | ||
<span>{userDetails.email}</span> | ||
</FlexItem> | ||
|
||
<FlexItem> | ||
<Title headingLevel="h2">Full Name:</Title> | ||
<span> | ||
{userDetails.firstName} {userDetails.lastName} | ||
</span> | ||
</FlexItem> | ||
<FlexItem> | ||
<Title headingLevel="h2">Role:</Title> | ||
<span>{withUserRole}</span> | ||
</FlexItem> | ||
</Flex> | ||
</FlexItem> | ||
|
||
<FlexItem> | ||
{/* <ProfilePicture | ||
tooltip={`Logged in as ${user.username}`} | ||
user={user} | ||
style={{ marginLeft: "1rem" }} | ||
width="100px" | ||
/> */} | ||
</FlexItem> | ||
</Flex> | ||
</CardBody> | ||
</Card> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters