mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 20:27:12 +00:00
Updated notifications
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from 'react';
|
||||||
import { faXmarkCircle } from "@fortawesome/free-solid-svg-icons";
|
import { faX } from '@fortawesome/free-solid-svg-icons';
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||||
import classnames from "classnames";
|
|
||||||
|
|
||||||
import { Notification as NotificationType } from "./NotificationProvider";
|
import { Notification as NotificationType } from './NotificationProvider';
|
||||||
|
|
||||||
interface NotificationProps {
|
interface NotificationProps {
|
||||||
notification: Required<NotificationType>;
|
notification: Required<NotificationType>;
|
||||||
@@ -12,7 +11,7 @@ interface NotificationProps {
|
|||||||
|
|
||||||
const Notification = ({
|
const Notification = ({
|
||||||
notification,
|
notification,
|
||||||
clearNotification,
|
clearNotification
|
||||||
}: NotificationProps) => {
|
}: NotificationProps) => {
|
||||||
const timeout = useRef<number>();
|
const timeout = useRef<number>();
|
||||||
|
|
||||||
@@ -37,22 +36,29 @@ const Notification = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={classnames(
|
className="relative w-full flex items-center justify-between px-4 py-6 rounded-md border border-bunker-500 pointer-events-auto bg-bunker-500"
|
||||||
"w-full flex items-center justify-between px-4 py-3 rounded pointer-events-auto",
|
|
||||||
{
|
|
||||||
"bg-green-600": notification.type === "success",
|
|
||||||
"bg-red-500": notification.type === "error",
|
|
||||||
"bg-blue-500": notification.type === "info",
|
|
||||||
}
|
|
||||||
)}
|
|
||||||
role="alert"
|
role="alert"
|
||||||
>
|
>
|
||||||
<p className="text-white text-sm font-bold">{notification.text}</p>
|
{notification.type === 'error' && (
|
||||||
|
<div className="absolute w-full h-1 bg-red top-0 left-0 rounded-t-md"></div>
|
||||||
|
)}
|
||||||
|
{notification.type === 'success' && (
|
||||||
|
<div className="absolute w-full h-1 bg-green top-0 left-0 rounded-t-md"></div>
|
||||||
|
)}
|
||||||
|
{notification.type === 'info' && (
|
||||||
|
<div className="absolute w-full h-1 bg-yellow top-0 left-0 rounded-t-md"></div>
|
||||||
|
)}
|
||||||
|
<p className="text-bunker-200 text-sm font-semibold mt-0.5">
|
||||||
|
{notification.text}
|
||||||
|
</p>
|
||||||
<button
|
<button
|
||||||
className="bg-white/5 rounded-lg p-3"
|
className="rounded-lg"
|
||||||
onClick={() => clearNotification(notification.text)}
|
onClick={() => clearNotification(notification.text)}
|
||||||
>
|
>
|
||||||
<FontAwesomeIcon className="text-white" icon={faXmarkCircle} />
|
<FontAwesomeIcon
|
||||||
|
className="text-white w-4 h-3 hover:text-red"
|
||||||
|
icon={faX}
|
||||||
|
/>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { createContext, ReactNode, useContext, useState } from "react";
|
import { createContext, ReactNode, useContext, useState } from 'react';
|
||||||
|
|
||||||
import Notifications from "./Notifications";
|
import Notifications from './Notifications';
|
||||||
|
|
||||||
type NotificationType = "success" | "error" | "info";
|
type NotificationType = 'success' | 'error' | 'info';
|
||||||
|
|
||||||
export type Notification = {
|
export type Notification = {
|
||||||
text: string;
|
text: string;
|
||||||
@@ -15,7 +15,7 @@ type NotificationContextState = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const NotificationContext = createContext<NotificationContextState>({
|
const NotificationContext = createContext<NotificationContextState>({
|
||||||
createNotification: () => console.log("createNotification not set!"),
|
createNotification: () => console.log('createNotification not set!')
|
||||||
});
|
});
|
||||||
|
|
||||||
export const useNotificationContext = () => useContext(NotificationContext);
|
export const useNotificationContext = () => useContext(NotificationContext);
|
||||||
@@ -37,8 +37,8 @@ const NotificationProvider = ({ children }: NotificationProviderProps) => {
|
|||||||
|
|
||||||
const createNotification = ({
|
const createNotification = ({
|
||||||
text,
|
text,
|
||||||
type = "success",
|
type = 'success',
|
||||||
timeoutMs = 2000,
|
timeoutMs = 5000
|
||||||
}: Notification) => {
|
}: Notification) => {
|
||||||
const doesNotifExist = notifications.some((notif) => notif.text === text);
|
const doesNotifExist = notifications.some((notif) => notif.text === text);
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ const NotificationProvider = ({ children }: NotificationProviderProps) => {
|
|||||||
return (
|
return (
|
||||||
<NotificationContext.Provider
|
<NotificationContext.Provider
|
||||||
value={{
|
value={{
|
||||||
createNotification,
|
createNotification
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Notifications
|
<Notifications
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import Notification from "./Notification";
|
import Notification from './Notification';
|
||||||
import { Notification as NotificationType } from "./NotificationProvider";
|
import { Notification as NotificationType } from './NotificationProvider';
|
||||||
|
|
||||||
interface NoticationsProps {
|
interface NoticationsProps {
|
||||||
notifications: Required<NotificationType>[];
|
notifications: Required<NotificationType>[];
|
||||||
@@ -8,14 +8,14 @@ interface NoticationsProps {
|
|||||||
|
|
||||||
const Notifications = ({
|
const Notifications = ({
|
||||||
notifications,
|
notifications,
|
||||||
clearNotification,
|
clearNotification
|
||||||
}: NoticationsProps) => {
|
}: NoticationsProps) => {
|
||||||
if (!notifications.length) {
|
if (!notifications.length) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="hidden fixed z-50 md:flex md:flex-col-reverse bottom-1 gap-y-2 w-96 h-full right-1 pointer-events-none">
|
<div className="hidden fixed z-50 md:flex md:flex-col-reverse bottom-1 gap-y-2 w-96 h-full right-2 bottom-2 pointer-events-none">
|
||||||
{notifications.map((notif) => (
|
{notifications.map((notif) => (
|
||||||
<Notification
|
<Notification
|
||||||
key={notif.text}
|
key={notif.text}
|
||||||
|
|||||||
Reference in New Issue
Block a user