Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[account] Export AccountUserDetails component #4227

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions docs/data/toolpad/core/components/account/AccountCustom.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import Typography from '@mui/material/Typography';
import useTheme from '@mui/material/styles/useTheme';
import { Account, AuthenticationContext, SessionContext } from '@toolpad/core';

const demoSession = {
Expand All @@ -13,6 +14,7 @@ const demoSession = {
export default function AccountCustom() {
const [session, setSession] = React.useState(demoSession);
const [signedOutSession, setSignedOutSession] = React.useState(null);
const theme = useTheme();

const authenticationSignedIn = React.useMemo(() => {
return {
Expand Down Expand Up @@ -60,12 +62,25 @@ export default function AccountCustom() {
Signed in
</Typography>
<SessionContext.Provider value={session}>
{/* preview-start */}
<Account
localeText={{
signInLabel: 'Login',
signOutLabel: 'Logout',
}}
slotProps={{
userDetailsContainer: {
sx: {
p: 2,
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
gap: 2,
'& .MuiStack-root': {
color: theme.palette.grey[700],
},
'& .MuiAvatar-root': {
border: `2px solid ${theme.palette.primary.contrastText}`,
boxShadow: theme.shadows[3],
},
},
},
signOutButton: {
color: 'info',
variant: 'outlined',
Expand All @@ -84,6 +99,7 @@ export default function AccountCustom() {
},
}}
/>
{/* preview-end */}
</SessionContext.Provider>

<Typography
Expand All @@ -95,12 +111,7 @@ export default function AccountCustom() {
</AuthenticationContext.Provider>
<AuthenticationContext.Provider value={authenticationSignedOut}>
<SessionContext.Provider value={signedOutSession}>
{/* preview-start */}
<Account
localeText={{
signInLabel: 'Login',
signOutLabel: 'Logout',
}}
slotProps={{
signInButton: {
color: 'info',
Expand All @@ -118,7 +129,6 @@ export default function AccountCustom() {
signOutButton: { color: 'primary', variant: 'outlined' },
}}
/>
{/* preview-end */}
</SessionContext.Provider>
</AuthenticationContext.Provider>
</div>
Expand Down
30 changes: 20 additions & 10 deletions docs/data/toolpad/core/components/account/AccountCustom.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import Typography from '@mui/material/Typography';
import useTheme from '@mui/material/styles/useTheme';
import {
Account,
AuthenticationContext,
Expand All @@ -20,6 +21,7 @@ export default function AccountCustom() {
const [signedOutSession, setSignedOutSession] = React.useState<Session | null>(
null,
);
const theme = useTheme();

const authenticationSignedIn = React.useMemo(() => {
return {
Expand Down Expand Up @@ -67,12 +69,25 @@ export default function AccountCustom() {
Signed in
</Typography>
<SessionContext.Provider value={session}>
{/* preview-start */}
<Account
localeText={{
signInLabel: 'Login',
signOutLabel: 'Logout',
}}
slotProps={{
userDetailsContainer: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about calling it just userDetails?

sx: {
p: 2,
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
gap: 2,
'& .MuiStack-root': {
color: theme.palette.grey[700],
},
'& .MuiAvatar-root': {
border: `2px solid ${theme.palette.primary.contrastText}`,
boxShadow: theme.shadows[3],
},
},
},
signOutButton: {
color: 'info',
variant: 'outlined',
Expand All @@ -91,6 +106,7 @@ export default function AccountCustom() {
},
}}
/>
{/* preview-end */}
</SessionContext.Provider>

<Typography
Expand All @@ -102,12 +118,7 @@ export default function AccountCustom() {
</AuthenticationContext.Provider>
<AuthenticationContext.Provider value={authenticationSignedOut}>
<SessionContext.Provider value={signedOutSession}>
{/* preview-start */}
<Account
localeText={{
signInLabel: 'Login',
signOutLabel: 'Logout',
}}
slotProps={{
signInButton: {
color: 'info',
Expand All @@ -125,7 +136,6 @@ export default function AccountCustom() {
signOutButton: { color: 'primary', variant: 'outlined' },
}}
/>
{/* preview-end */}
</SessionContext.Provider>
</AuthenticationContext.Provider>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
<Account
localeText={{
signInLabel: 'Login',
signOutLabel: 'Logout',
}}
slotProps={{
signInButton: {
userDetailsContainer: {
sx: {
p: 2,
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
gap: 2,
'& .MuiStack-root': {
color: theme.palette.grey[700],
},
'& .MuiAvatar-root': {
border: `2px solid ${theme.palette.primary.contrastText}`,
boxShadow: theme.shadows[3],
},
},
},
signOutButton: {
color: 'info',
variant: 'outlined',
sx: {
margin: 'auto',
color: 'primaryDark',
textTransform: 'capitalize',
fontFamily: 'Inter',
fontSize: '1em',
height: 'fit-content',
maxHeight: 'max-content',
},
},
signOutButton: { color: 'primary', variant: 'outlined' },
iconButton: {
sx: {
width: 'fit-content',
margin: 'auto',
},
},
}}
/>
113 changes: 113 additions & 0 deletions docs/data/toolpad/core/components/account/AccountCustomUserDetails.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { Box, Stack, Typography, Avatar, Link } from '@mui/material';
import { Account, AuthenticationContext, SessionContext } from '@toolpad/core';

const demoSession = {
user: {
name: 'Bharat Kashyap',
email: 'bharat@mui.com',
image: 'https://avatars.githubusercontent.com/u/19550456',
},
org: {
name: 'MUI Inc.',
url: 'https://mui.com',
logo: 'https://mui.com/static/logo.svg',
},
};

function UserDetailsContainer({ session }) {
if (!session?.user) {
return <Typography>No user session available</Typography>;
}
const { name, email, image } = session.user;
const { logo: orgLogo, name: orgName, url: orgUrl } = session.org;

return (
<Box sx={{ p: 2 }}>
<Stack>
<Stack flexDirection="row" gap={2} justifyContent="flex-start" mb={2}>
<Avatar src={image ?? ''} alt={name ?? ''} />
<Stack>
<Typography fontWeight="bolder">{name}</Typography>
<Typography variant="caption" color="text.secondary">
{email}
</Typography>
</Stack>
</Stack>
{session.org && (
<Stack>
<Typography textAlign="center" fontSize="0.625rem" gutterBottom>
This account is managed by
</Typography>
<Box display="flex" justifyContent="center" alignItems="center" gap={2}>
<Avatar
variant="square"
src={orgLogo}
alt={orgName}
sx={{ width: 27, height: 24 }}
/>
<Stack>
<Typography variant="caption" fontWeight="bolder">
{orgName}
</Typography>
<Link
variant="caption"
href={orgUrl}
target="_blank"
rel="noopener noreferrer"
>
{orgUrl}
</Link>
</Stack>
</Box>
</Stack>
)}
</Stack>
</Box>
);
}

UserDetailsContainer.propTypes = {
session: PropTypes.shape({
org: PropTypes.shape({
logo: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
url: PropTypes.string.isRequired,
}).isRequired,
user: PropTypes.shape({
email: PropTypes.string,
id: PropTypes.string,
image: PropTypes.string,
name: PropTypes.string,
}),
}).isRequired,
};

export default function AccountCustomUserDetails() {
const [session, setSession] = React.useState(demoSession);
const authentication = React.useMemo(() => {
return {
signIn: () => {
setSession(demoSession);
},
signOut: () => {
setSession(null);
},
};
}, []);

return (
<AuthenticationContext.Provider value={authentication}>
<SessionContext.Provider value={session}>
{/* preview-start */}
<Account
slots={{
userDetailsContainer: UserDetailsContainer,
}}
/>
{/* preview-end */}
</SessionContext.Provider>
</AuthenticationContext.Provider>
);
}
Loading
Loading