-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
299 additions
and
18 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
20 changes: 20 additions & 0 deletions
20
packages/mrwhale-dashboard/src/features/client/clientApi.ts
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,20 @@ | ||
import { api } from "../../shared/api"; | ||
import { User } from "../../types/user"; | ||
|
||
interface ClientResponse { | ||
user: User | null; | ||
clientId: string; | ||
userCount: number; | ||
version: string; | ||
} | ||
|
||
export const clientApi = api.injectEndpoints({ | ||
endpoints: (build) => ({ | ||
getClientInfo: build.mutation<ClientResponse, void>({ | ||
query: () => `client`, | ||
}), | ||
}), | ||
overrideExisting: false, | ||
}); | ||
|
||
export const { useGetClientInfoMutation } = clientApi; |
43 changes: 43 additions & 0 deletions
43
packages/mrwhale-dashboard/src/features/client/clientSlice.ts
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,43 @@ | ||
import { createSlice } from "@reduxjs/toolkit"; | ||
|
||
import type { RootState } from "../../store"; | ||
import { User } from "../../types/user"; | ||
import { clientApi } from "./clientApi"; | ||
|
||
const CLIENT_FEATURE_KEY = "Client"; | ||
|
||
type ClientState = { | ||
user: User | null; | ||
clientId: string; | ||
userCount: number; | ||
version: string; | ||
}; | ||
|
||
const slice = createSlice({ | ||
name: CLIENT_FEATURE_KEY, | ||
initialState: { | ||
user: null, | ||
clientId: "", | ||
userCount: 0, | ||
version: "", | ||
} as ClientState, | ||
reducers: {}, | ||
extraReducers: (builder) => { | ||
builder.addMatcher( | ||
clientApi.endpoints.getClientInfo.matchFulfilled, | ||
(state, { payload }) => { | ||
state.user = payload.user; | ||
state.clientId = payload.clientId; | ||
state.userCount = payload.userCount; | ||
state.version = payload.version; | ||
} | ||
); | ||
}, | ||
}); | ||
|
||
export default slice.reducer; | ||
|
||
export const selectClientUser = (state: RootState) => state.client.user; | ||
export const selectClientId = (state: RootState) => state.client.clientId; | ||
export const selectUserCount = (state: RootState) => state.client.userCount; | ||
export const selectVersion = (state: RootState) => state.client.version; |
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,4 @@ | ||
.feature-image { | ||
max-width: 100%; | ||
border-radius: 10px; | ||
} |
83 changes: 83 additions & 0 deletions
83
packages/mrwhale-dashboard/src/features/home/FeatureItem.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,83 @@ | ||
import { | ||
Avatar, | ||
Box, | ||
Fade, | ||
Grid, | ||
List, | ||
ListItem, | ||
ListItemAvatar, | ||
ListItemText, | ||
Typography, | ||
} from "@mui/material"; | ||
import { useState } from "react"; | ||
import VizSensor from "react-visibility-sensor"; | ||
|
||
import "./FeatureItem.css"; | ||
|
||
export interface FeatureItemProps { | ||
title: string; | ||
description: string; | ||
imageSrc: string; | ||
imageAlt: string; | ||
list?: { | ||
icon: JSX.Element; | ||
primaryText: string; | ||
secondaryText?: string; | ||
}[]; | ||
} | ||
|
||
const FeatureItem = ({ | ||
title, | ||
description, | ||
imageSrc, | ||
imageAlt, | ||
list, | ||
}: FeatureItemProps) => { | ||
const [active, setActive] = useState(false); | ||
return ( | ||
<VizSensor | ||
onChange={(isVisible: boolean) => { | ||
if (isVisible) { | ||
setActive(true); | ||
} | ||
}} | ||
> | ||
<Fade in={active} timeout={2000}> | ||
<Box sx={{ display: "flex", mb: 20 }}> | ||
<Grid container spacing={4}> | ||
<Grid item xs={12} md={6} lg={6}> | ||
<Typography variant="h3" color="text.primary" paragraph> | ||
{title} | ||
</Typography> | ||
<Typography variant="body1" color="text.primary" paragraph> | ||
{description} | ||
</Typography> | ||
{list && ( | ||
<List > | ||
{list.map((item) => ( | ||
<ListItem> | ||
<ListItemAvatar> | ||
<Avatar>{item.icon}</Avatar> | ||
</ListItemAvatar> | ||
<ListItemText | ||
primary={item.primaryText} | ||
secondary={ | ||
item.secondaryText ? item.secondaryText : null | ||
} | ||
/> | ||
</ListItem> | ||
))} | ||
</List> | ||
)} | ||
</Grid> | ||
<Grid item xs={12} md={6} lg={6}> | ||
<img src={imageSrc} alt={imageAlt} className="feature-image" /> | ||
</Grid> | ||
</Grid> | ||
</Box> | ||
</Fade> | ||
</VizSensor> | ||
); | ||
}; | ||
|
||
export default FeatureItem; |
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,23 @@ | ||
import { useMemo } from "react"; | ||
import { useSelector } from "react-redux"; | ||
|
||
import { | ||
selectClientUser, | ||
selectClientId, | ||
selectUserCount, | ||
selectVersion, | ||
} from "../features/client/clientSlice"; | ||
|
||
export const useClient = () => { | ||
const user = useSelector(selectClientUser); | ||
const clientId = useSelector(selectClientId); | ||
const userCount = useSelector(selectUserCount); | ||
const version = useSelector(selectVersion); | ||
|
||
return useMemo(() => ({ user, clientId, userCount, version }), [ | ||
user, | ||
clientId, | ||
userCount, | ||
version, | ||
]); | ||
}; |
Oops, something went wrong.