-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: split PageContainer into RootAppLayout, useAuthRefresh, and AppBar
- Loading branch information
1 parent
ce8cf20
commit a00b3a7
Showing
35 changed files
with
974 additions
and
678 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { | ||
withNavDecorator, | ||
withAppStateInfoDecorator, | ||
type AppStateInfoDecoratorArgs, | ||
} from "@/../.storybook/decorators"; | ||
import { QUERIES } from "@/graphql/queries"; | ||
import { STATIC_MOCK_USERS } from "@/tests/mockItems/staticMockUsers"; | ||
import { AppBar } from "./AppBar"; | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
const meta = { | ||
title: "Components/AppBar/AppBar", | ||
component: AppBar, | ||
decorators: [withNavDecorator, withAppStateInfoDecorator], | ||
args: { | ||
_mock_apollo_decorator_args: { | ||
mocks: [ | ||
{ | ||
request: { query: QUERIES.MY_PROFILE }, | ||
result: { | ||
data: { | ||
myProfile: STATIC_MOCK_USERS.Guy_McPerson.profile, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
} satisfies Meta<AppStateInfoDecoratorArgs>; | ||
|
||
export default meta; | ||
|
||
/////////////////////////////////////////////////////////// | ||
// STORIES | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const UserNotAuthenticated = { | ||
args: { | ||
_app_state_info_decorator_args: { | ||
appState: { | ||
isUserAuthenticated: false, | ||
isAccountActive: false, | ||
isConnectOnboardingComplete: false, | ||
}, | ||
}, | ||
}, | ||
} satisfies Story; | ||
|
||
export const InactiveSubscription = { | ||
args: { | ||
_app_state_info_decorator_args: { | ||
appState: { | ||
isUserAuthenticated: true, | ||
isAccountActive: false, | ||
isConnectOnboardingComplete: false, | ||
}, | ||
}, | ||
}, | ||
} satisfies Story; | ||
|
||
export const StripeConnectOnboardingIncomplete = { | ||
args: { | ||
_app_state_info_decorator_args: { | ||
appState: { | ||
isUserAuthenticated: true, | ||
isAccountActive: true, | ||
isConnectOnboardingComplete: false, | ||
}, | ||
}, | ||
}, | ||
} satisfies Story; | ||
|
||
export const FullyOnboardedActiveUser = { | ||
args: { | ||
_app_state_info_decorator_args: { | ||
appState: { | ||
isUserAuthenticated: true, | ||
isAccountActive: true, | ||
isConnectOnboardingComplete: true, | ||
}, | ||
}, | ||
}, | ||
} satisfies Story; |
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,44 @@ | ||
import { styled } from "@mui/material/styles"; | ||
import Text, { typographyClasses } from "@mui/material/Typography"; | ||
import { Logo, brandingClassNames } from "@/components/Branding"; | ||
import { Anchor } from "@/components/Navigation/Anchor"; | ||
import { APP_PATHS } from "@/routes/appPaths"; | ||
import { isAuthenticatedStore } from "@/stores"; | ||
|
||
export const AppBarLogoButton = () => { | ||
const isAuthenticated = isAuthenticatedStore.useSubToStore(); | ||
|
||
return ( | ||
<StyledDiv> | ||
<Anchor href={isAuthenticated ? APP_PATHS.HOME : APP_PATHS.ROOT}> | ||
<Logo /> | ||
<Text variant="h1">Fixit</Text> | ||
</Anchor> | ||
</StyledDiv> | ||
); | ||
}; | ||
|
||
const StyledDiv = styled("div")(({ theme: { palette, variables } }) => ({ | ||
display: "flex", | ||
flexDirection: "row", | ||
alignItems: "center", | ||
|
||
"& > a": { | ||
// Increase the anchor's default hover-opacity (0.7) | ||
"&:hover": { | ||
opacity: 0.75, | ||
}, | ||
|
||
[`& > .${brandingClassNames.fixitLogoImg}`]: { | ||
height: variables.isMobilePageLayout ? "2.75rem" : "2.25rem", | ||
border: "1px solid white", | ||
}, | ||
|
||
[`& > .${typographyClasses.root}`]: { | ||
margin: "0 auto 0 0.5rem", | ||
fontSize: "1.5rem", | ||
fontWeight: 400, | ||
color: palette.text.primary, | ||
}, | ||
}, | ||
})); |
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,15 @@ | ||
import { usePageLayoutContext } from "@/app/PageLayoutContext/usePageLayoutContext"; | ||
import { DesktopAppBarMenu } from "./DesktopAppBarMenu"; | ||
import { MobileAppBarMenu } from "./MobileAppBarMenu"; | ||
|
||
/** | ||
* This component returns an AppBar menu component which is appropriate for the device/viewport. | ||
* | ||
* - When `isMobilePageLayout` is `true`: returns {@link MobileAppBarMenu} | ||
* - When `isMobilePageLayout` is `false`: returns {@link DesktopAppBarMenu} | ||
*/ | ||
export const AppBarMenu = () => { | ||
const { isMobilePageLayout } = usePageLayoutContext(); | ||
|
||
return isMobilePageLayout ? <MobileAppBarMenu /> : <DesktopAppBarMenu />; | ||
}; |
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,77 @@ | ||
import { styled } from "@mui/material/styles"; | ||
import Switch, { switchClasses as muiSwitchClasses } from "@mui/material/Switch"; | ||
import Tooltip from "@mui/material/Tooltip"; | ||
import LightModeIcon from "@mui/icons-material/LightMode"; | ||
import DarkModeIcon from "@mui/icons-material/ModeNightSharp"; | ||
import { THEME_NAMES } from "@/app/ThemeProvider/themes"; | ||
import { themeStore } from "@/stores"; | ||
import { appBarMenuElementIDs } from "./elementIDs"; | ||
|
||
export const DarkModeSwitch = () => { | ||
const currentTheme = themeStore.useSubToStore(); | ||
|
||
const handleChange = () => themeStore.toggle(currentTheme); | ||
|
||
return ( | ||
<Tooltip title="Toggle dark mode"> | ||
<StyledSwitch | ||
id={appBarMenuElementIDs.darkModeSwitch} // <-- Chrome logs a warning if this is not set | ||
checked={currentTheme === THEME_NAMES.DARK} | ||
checkedIcon={<DarkModeIcon />} | ||
icon={<LightModeIcon />} | ||
onChange={handleChange} | ||
inputProps={{ "aria-label": "dark mode switch" }} | ||
/> | ||
</Tooltip> | ||
); | ||
}; | ||
|
||
const StyledSwitch = styled(Switch)(({ theme: { palette } }) => ({ | ||
width: "65px", | ||
height: "34px", | ||
padding: "7px", | ||
|
||
[`& > .${muiSwitchClasses.switchBase}`]: { | ||
height: "33px", | ||
width: "33px", | ||
paddingRight: "10px", // <-- Nudges LightModeIcon to the left a bit, not aligning for some reason. | ||
transform: "translateX(6px)", | ||
borderWidth: "2px", | ||
borderStyle: "solid", | ||
borderColor: palette.mode === "dark" ? "rgba(0, 0, 0, 0.7)" : "rgba(255, 255, 255, 0.7)", | ||
opacity: 1, | ||
backgroundColor: palette.primary.main, | ||
|
||
"&:hover": { | ||
opacity: 1, | ||
backgroundColor: palette.primary.dark, | ||
}, | ||
|
||
// WHEN CHECKED: | ||
[`&.${muiSwitchClasses.checked}`]: { | ||
opacity: 1, | ||
transform: "translateX(30px)", | ||
backgroundColor: palette.primary.dark, | ||
|
||
"&:hover": { | ||
opacity: 1, | ||
backgroundColor: palette.primary.main, | ||
}, | ||
|
||
// Styles applied to the `DarkModeIcon`: | ||
"& > svg": { | ||
position: "absolute", | ||
top: "4px", | ||
left: "1px", | ||
height: "1.5rem", | ||
width: "1.5rem", | ||
color: palette.text.primary, | ||
transform: "rotateZ(140deg)", | ||
}, | ||
}, | ||
}, | ||
|
||
[`& .${muiSwitchClasses.track}`]: { | ||
borderRadius: 10, | ||
}, | ||
})); |
Oops, something went wrong.