Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { ColumnDef } from "@tanstack/react-table"
- import { MoreHorizontal } from "lucide-react"
- import axios from "axios";
- import { AxiosError } from 'axios'; // Import AxiosError type
- import { Button } from "@/components/ui/button"
- import Snackbar from '@mui/material/Snackbar';
- import Alert from '@mui/material/Alert';
- import SnackbarContent from '@mui/material/SnackbarContent';
- import React, { useState } from 'react';
- import { useRouter } from "next/navigation";
- import toast, { Toaster } from 'react-hot-toast';
- import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuLabel,
- DropdownMenuSeparator,
- DropdownMenuTrigger,
- } from "@/components/ui/dropdown-menu"
- const ActionAllPackages = (paket) => {
- const router = useRouter();
- const handleCloseSnackbar = () => {
- const handleCopyPackagaName = (dependency) => {
- navigator.clipboard.writeText(dependency)
- .then(() => {
- toast.success("Copied package name!")
- })
- .catch(error => {
- toast.error("Failed to copy the package name...")
- });
- }
- const copyLink = () => {
- const selectedPackage = paket;
- // Return a new Promise
- return new Promise((resolve, reject) => {
- setTimeout(() => {
- navigator.clipboard.writeText(paket.link)
- .then(() => {
- // Resolve the promise if copying is successful
- resolve(paket.link);
- })
- .catch(error => {
- // Reject the promise if copying fails
- console.log("COPY-ERROR: ", error);
- reject(error);
- });
- }, 1000);
- });
- };
- const handleCopyInstallLink = (e) => {
- const copyPromise = copyLink();
- toast.promise(
- copyPromise,
- {
- loading: 'Copying...',
- success: <b>Copied the install link!</b>,
- error: <b>Could not copy the install link!</b>,
- }
- );
- };
- const handleDetailedView = () => {
- router.push(`/detailed_view?name=${paket.name}`);
- };
- return (
- <div>
- <Toaster position="bottom-right" reverseOrder={false} />
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button variant="ghost" className="h-8 w-8 p-0">
- <span className="sr-only">Open menu</span>
- <MoreHorizontal className="h-4 w-4" />
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <DropdownMenuLabel>Actions</DropdownMenuLabel>
- <DropdownMenuItem
- onClick={() => handleCopyPackagaName(paket.name)}
- >
- Copy package name
- </DropdownMenuItem>
- <DropdownMenuItem
- onClick={handleCopyInstallLink}
- >
- Copy install link
- </DropdownMenuItem>
- <DropdownMenuSeparator />
- <DropdownMenuItem
- onClick={handleDetailedView}
- >
- Detailed view
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- </div>
- )
- }
- export default ActionAllPackages;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement