Skip to content

Commit

Permalink
fix: add refresh db to sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
nimit9 committed Aug 25, 2024
1 parent 0211b1f commit 5399ddf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/actions/refresh-db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { checkUserEmailForPurchase } from '@/utiles/appx-check-mail';
import { Course } from '@prisma/client';
import { getServerSession } from 'next-auth';

type RefreshDbFn = (args: { userId: string; email: string }) => Promise<{
type RefreshDbFn = () => Promise<{
error: boolean;
message: string;
}>;
Expand Down
25 changes: 24 additions & 1 deletion src/components/sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {
History,
PanelRightOpen,
LogOut,
RefreshCcw,
} from 'lucide-react';
import { toast } from 'sonner';
import { refreshDb } from '@/actions/refresh-db';

export const menuOptions = [
{ id: 1, name: 'My Courses', Component: Library, href: '/my-courses' },
Expand All @@ -23,6 +26,15 @@ export const menuOptions = [
export const MenuOptions = () => {
const [expanded, setExpanded] = useState(true);

const handleRefresh = async () => {
const res = await refreshDb();
if (res.error) {
toast.error(res.message);
} else {
toast.info(res.message);
}
};

return (
<aside className="h-screen">
<nav className="flex h-full flex-col border-r bg-white shadow-sm dark:bg-[#020817]">
Expand All @@ -47,7 +59,18 @@ export const MenuOptions = () => {
<AnimatedTooltip expanded={expanded} items={menuOptions} />
</div>

<div className="border-t p-4">
<div className="flex flex-col gap-2 border-t p-4">
<div className="flex p-2">
<RefreshCcw size={24} />
<button
onClick={handleRefresh}
className={`flex items-center justify-between overflow-hidden transition-all ${
expanded ? 'ml-3 w-52' : 'w-0'
}`}
>
<h4 className="font-semibold">Refresh DB</h4>
</button>
</div>
<div className="flex rounded-md p-2">
<LogOut size={24} color="#DD503F" />
<button
Expand Down

0 comments on commit 5399ddf

Please sign in to comment.