-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🪟 🎉 Display "Credits" in sidebar and add info when user is running ou…
…t of credits (#20595) * 🪟 🎉 Display "Credits" in sidebar and add info when user is running out of credits Demo: https://www.loom.com/share/ca43d6b72dcc42208add0bd91e1b1efc
- Loading branch information
1 parent
8a42960
commit 74be2f8
Showing
8 changed files
with
113 additions
and
22 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
12 changes: 12 additions & 0 deletions
12
...iews/credits/CreditsPage/components/LowCreditBalanceHint/LowCreditBalanceHint.module.scss
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,12 @@ | ||
@use "scss/colors"; | ||
|
||
.container { | ||
width: 100%; | ||
} | ||
|
||
.wrapper { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
width: 100%; | ||
} |
36 changes: 36 additions & 0 deletions
36
.../cloud/views/credits/CreditsPage/components/LowCreditBalanceHint/LowCreditBalanceHint.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,36 @@ | ||
import { faCreditCard, faWarning } from "@fortawesome/free-solid-svg-icons"; | ||
import { FormattedMessage } from "react-intl"; | ||
|
||
import { InfoBox } from "components/ui/InfoBox"; | ||
|
||
import { useGetCloudWorkspace } from "packages/cloud/services/workspaces/CloudWorkspacesService"; | ||
import { useCurrentWorkspace } from "services/workspaces/WorkspacesService"; | ||
|
||
import styles from "./LowCreditBalanceHint.module.scss"; | ||
|
||
export const LOW_BALANCE_CREDIT_TRESHOLD = 20; | ||
|
||
export const LowCreditBalanceHint: React.FC<React.PropsWithChildren<unknown>> = ({ children }) => { | ||
const workspace = useCurrentWorkspace(); | ||
const cloudWorkspace = useGetCloudWorkspace(workspace.workspaceId); | ||
|
||
if (cloudWorkspace.remainingCredits > LOW_BALANCE_CREDIT_TRESHOLD) { | ||
return null; | ||
} | ||
|
||
const status = cloudWorkspace.remainingCredits <= 0 ? "zeroBalance" : "lowBalance"; | ||
const variant = status === "zeroBalance" ? "error" : "default"; | ||
|
||
const ICONS = { | ||
lowBalance: faCreditCard, | ||
zeroBalance: faWarning, | ||
}; | ||
return ( | ||
<InfoBox className={styles.container} icon={ICONS[status]} variant={variant}> | ||
<div className={styles.wrapper}> | ||
<FormattedMessage id={`credits.${status}`} /> | ||
{children} | ||
</div> | ||
</InfoBox> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
...pp/src/packages/cloud/views/credits/CreditsPage/components/LowCreditBalanceHint/index.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 @@ | ||
export { LowCreditBalanceHint } from "./LowCreditBalanceHint"; |
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