Skip to content

Commit

Permalink
⬇️ Updated toast
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Feb 10, 2024
1 parent c72a8e2 commit efe7b06
Show file tree
Hide file tree
Showing 16 changed files with 512 additions and 148 deletions.
4 changes: 3 additions & 1 deletion apps/webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@ant-design/icons": "^5.2.6",
"@faker-js/faker": "^8.3.1",
"@hookform/resolvers": "^3.3.2",
"@panora/shared": "workspace:*",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
Expand All @@ -37,6 +38,7 @@
"cmdk": "^0.2.0",
"date-fns": "^2.30.0",
"lucide-react": "^0.293.0",
"next-themes": "^0.2.1",
"posthog-js": "^1.96.1",
"react": "^18.2.0",
"react-day-picker": "^8.9.1",
Expand All @@ -46,7 +48,7 @@
"react-hot-toast": "^2.4.1",
"react-router-dom": "^6.20.0",
"recharts": "^2.10.1",
"@panora/shared": "workspace:*",
"sonner": "^1.4.0",
"tailwind-merge": "^2.0.0",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.22.4",
Expand Down
18 changes: 0 additions & 18 deletions apps/webapp/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import LogsPage from './components/events';
import ConnectionsPage from './components/connections';
import TaskPage from './components/events/EventsTable';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { Toaster } from 'react-hot-toast';
import { RootLayout } from './components/root-layout';
import ConfigurationPage from './components/configuration';
import ApiKeysPage from './components/api-keys';
Expand Down Expand Up @@ -33,23 +32,6 @@ function App() {
return (
<QueryClientProvider client={queryClient}>
<ThemeProvider defaultTheme='dark' storageKey='vite-ui-theme'>
<Toaster
position='bottom-right'
reverseOrder={false}
gutter={8}
containerClassName=''
containerStyle={{}}
toastOptions={{
// Define default options
className: '',
duration: 3000,
style: {
background: '#0A0A0B',
color: '#fff',
border: '0.03rem solid white',
},
}}
/>
<Router>
<Routes>
<Route path='/' element={<RootLayout />}>
Expand Down
38 changes: 27 additions & 11 deletions apps/webapp/src/components/connections/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
import { Button } from "../ui/button";
import ConnectionTable from "./ConnectionTable";
import { toast } from "sonner"

export default function ConnectionsPage() {
return (
<div className="flex items-center justify-between space-y-2">
<div className="flex-1 space-y-4 p-8 pt-6">
<div className="flex flex-col items-start justify-between space-y-2">
<h2 className="text-3xl font-bold tracking-tight">Connections</h2>
<h2 className="text-lg font-bold tracking-tight">Connections between your product and your users’ accounts on third-party software.</h2>
</div>
<ConnectionTable/>
</div>
return (
<div className="flex items-center justify-between space-y-2">
<div className="flex-1 space-y-4 p-8 pt-6">
<div className="flex flex-col items-start justify-between space-y-2">
<h2 className="text-3xl font-bold tracking-tight">Connections</h2>
<h2 className="text-lg font-bold tracking-tight">Connections between your product and your users’ accounts on third-party software.</h2>
<Button
variant="outline"
onClick={() =>
toast("Event has been created", {
description: "Sunday, December 03, 2023 at 9:00 AM",
action: {
label: "Undo",
onClick: () => console.log("Undo"),
},
})
}
>
Show Toast
</Button>
</div>
<ConnectionTable />
</div>
);
}
</div>
);
}
142 changes: 71 additions & 71 deletions apps/webapp/src/components/homepage/components/user-nav.tsx
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
import {
Avatar,
AvatarFallback,
AvatarImage,
} from "@/components/ui/avatar"
import { Button } from "@/components/ui/button"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
Avatar,
AvatarFallback,
AvatarImage,
} from "@/components/ui/avatar"
import { Button } from "@/components/ui/button"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { Skeleton } from "@/components/ui/skeleton";
import useProfile from "@/hooks/useProfile";
import useProfileStore from "@/state/profileStore";
import { useEffect } from "react";

export function UserNav() {
const {data, isLoading} = useProfile();
if(!data) {
console.log("loading profiles");
}
const { profile, setProfile } = useProfileStore();
export function UserNav() {
const {data, isLoading} = useProfile();
if(!data) {
console.log("loading profiles");
}
const { profile, setProfile } = useProfileStore();

useEffect(()=> {
if(data && data.length > 0 ){
setProfile({
id_user: data[0].id_user,
email: data[0].email,
first_name: data[0].first_name,
last_name: data[0].last_name,
id_organization: data[0].id_organization as string,
})
}
}, [data, setProfile]);
useEffect(()=> {
if(data && data.length > 0 ){
setProfile({
id_user: data[0].id_user,
email: data[0].email,
first_name: data[0].first_name,
last_name: data[0].last_name,
id_organization: data[0].id_organization as string,
})
}
}, [data, setProfile]);

return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="relative h-8 w-8 rounded-full">
<Avatar className="h-8 w-8">
<AvatarImage src="/avatars/01.png" alt="@shadcn" />
<AvatarFallback>SC</AvatarFallback>
</Avatar>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-56 ml-10" align="end" forceMount>
<DropdownMenuLabel className="font-normal">
<div className="flex flex-col space-y-1">
<p className="text-sm font-medium leading-none">
{profile ? profile.first_name : isLoading ? <Skeleton className="w-[100px] h-[20px] rounded-md" /> : "No profiles found"}

</p>
<p className="text-xs leading-none text-muted-foreground">
{profile ? profile.email : isLoading ? <Skeleton className="w-[100px] h-[20px] rounded-md" /> : "No mail found"}
</p>
</div>
</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuGroup>
<DropdownMenuItem>
Profile
</DropdownMenuItem>
<DropdownMenuItem>
Billing
</DropdownMenuItem>
<DropdownMenuItem>
Settings
</DropdownMenuItem>
</DropdownMenuGroup>
<DropdownMenuSeparator />
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="relative h-8 w-8 rounded-full">
<Avatar className="h-8 w-8">
<AvatarImage src="/avatars/01.png" alt="@shadcn" />
<AvatarFallback>SC</AvatarFallback>
</Avatar>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-56 ml-10" align="end" forceMount>
<DropdownMenuLabel className="font-normal">
<div className="flex flex-col space-y-1">
<p className="text-sm font-medium leading-none">
{profile ? profile.first_name : isLoading ? <Skeleton className="w-[100px] h-[20px] rounded-md" /> : "No profiles found"}

</p>
<p className="text-xs leading-none text-muted-foreground">
{profile ? profile.email : isLoading ? <Skeleton className="w-[100px] h-[20px] rounded-md" /> : "No mail found"}
</p>
</div>
</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuGroup>
<DropdownMenuItem>
Profile
</DropdownMenuItem>
<DropdownMenuItem>
Billing
</DropdownMenuItem>
<DropdownMenuItem>
Log out
Settings
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)
}
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuItem>
Log out
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)
}
4 changes: 3 additions & 1 deletion apps/webapp/src/components/root-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { UserNav } from './homepage/components/user-nav';
import TeamSwitcher from './shared/team-switcher';
import { Outlet, useNavigate } from 'react-router-dom';
import { ThemeSwitcher } from './theme-switcher';
import { Toaster } from "@/components/ui/sonner"

export const RootLayout = () => {
const [windowWidth, setWindowWidth] = useState(window.innerWidth);
Expand Down Expand Up @@ -32,7 +33,7 @@ export const RootLayout = () => {
) : (
<div className='items-center hidden lg:flex lg:flex-col border-r fixed left-0 bg-opacity-90 backdrop-filter backdrop-blur-lg w-[200px] h-screen'>
<div className='flex lg:flex-col items-center py-4 space-y-4'>
<div className='flex flex-row justify-between items-center w-full px-4'>
<div className='flex flex-row justify-between items-center w-full px-6'>
<img src='logo.png' className='w-14' />
<ThemeSwitcher />
</div>
Expand All @@ -50,6 +51,7 @@ export const RootLayout = () => {
<div className='flex-1 space-y-4 pt-6 px-10 lg:ml-[200px]'>
<Outlet />
</div>
<Toaster />
</div>
);
};
29 changes: 29 additions & 0 deletions apps/webapp/src/components/ui/sonner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useTheme } from "next-themes"
import { Toaster as Sonner } from "sonner"

type ToasterProps = React.ComponentProps<typeof Sonner>

const Toaster = ({ ...props }: ToasterProps) => {
const { theme = "system" } = useTheme()

return (
<Sonner
theme={theme as ToasterProps["theme"]}
className="toaster group"
toastOptions={{
classNames: {
toast:
"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
description: "group-[.toast]:text-muted-foreground",
actionButton:
"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
cancelButton:
"group-[.toast]:bg-muted group-[.toast]:text-muted-foreground",
},
}}
{...props}
/>
)
}

export { Toaster }
26 changes: 22 additions & 4 deletions apps/webapp/src/hooks/mutations/useApiKeyMutation.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import config from '@/utils/config';
import { useMutation } from '@tanstack/react-query';
import toast from 'react-hot-toast';
import { toast } from "sonner"

interface IApiKeyDto {
projectId: string;
Expand Down Expand Up @@ -44,13 +44,31 @@ const useApiKeyMutation = () => {
return useMutation({
mutationFn: addApiKey,
onMutate: () => {
toast('Adding api key...');
toast("Api key is being generated !", {
description: "",
action: {
label: "Close",
onClick: () => console.log("Close"),
},
})
},
onError: (error) => {
toast.error(`Error: ${error.message}`);
toast("Api key generation failed !", {
description: error.message,
action: {
label: "Close",
onClick: () => console.log("Close"),
},
})
},
onSuccess: () => {
toast.success('Api Key added successfully!');
toast("Api key has been generated !", {
description: "",
action: {
label: "Close",
onClick: () => console.log("Close"),
},
})
},
onSettled: () => {
},
Expand Down
26 changes: 22 additions & 4 deletions apps/webapp/src/hooks/mutations/useDefineFieldMutation.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import config from '@/utils/config';
import { useMutation } from '@tanstack/react-query';
import toast from 'react-hot-toast';
import { toast } from "sonner"

interface IDefineTargetFieldDto{
object_type_owner: string;
Expand Down Expand Up @@ -28,13 +28,31 @@ const useDefineFieldMutation = () => {
return useMutation({
mutationFn: defineField,
onMutate: () => {
toast('Defining field...');
toast("Field mapping is being defined !", {
description: "",
action: {
label: "Close",
onClick: () => console.log("Close"),
},
})
},
onError: (error) => {
toast.error(`Error: ${error.message}`);
toast("Field mapping definition failed !", {
description: error.message,
action: {
label: "Close",
onClick: () => console.log("Close"),
},
})
},
onSuccess: () => {
toast.success('Field mapping defined successfully!');
toast("Field mapping has been defined !", {
description: "",
action: {
label: "Close",
onClick: () => console.log("Close"),
},
})
},
onSettled: () => {
},
Expand Down
Loading

0 comments on commit efe7b06

Please sign in to comment.