diff --git a/package-lock.json b/package-lock.json index 1be01808..49d09781 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48,7 +48,6 @@ "qrcode.react": "^3.1.0", "react": "18.2.0", "react-copy-to-clipboard": "^5.1.0", - "react-datepicker": "^4.21.0", "react-dom": "18.2.0", "react-hot-toast": "^2.4.0", "react-timeago": "^7.1.0", @@ -2151,15 +2150,6 @@ "@noble/hashes": "^1.1.5" } }, - "node_modules/@popperjs/core": { - "version": "2.11.8", - "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz", - "integrity": "sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==", - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/popperjs" - } - }, "node_modules/@prisma/client": { "version": "5.12.1", "resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.12.1.tgz", @@ -4025,21 +4015,6 @@ "node": ">=12" } }, - "node_modules/date-fns": { - "version": "2.30.0", - "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz", - "integrity": "sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==", - "dependencies": { - "@babel/runtime": "^7.21.0" - }, - "engines": { - "node": ">=0.11" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/date-fns" - } - }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -8206,23 +8181,6 @@ "react": "^15.3.0 || 16 || 17 || 18" } }, - "node_modules/react-datepicker": { - "version": "4.23.0", - "resolved": "https://registry.npmjs.org/react-datepicker/-/react-datepicker-4.23.0.tgz", - "integrity": "sha512-w+msqlOZ14v6H1UknTKtZw/dw9naFMgAOspf59eY130gWpvy5dvKj/bgsFICDdvxB7PtKWxDcbGlAqCloY1d2A==", - "dependencies": { - "@popperjs/core": "^2.11.8", - "classnames": "^2.2.6", - "date-fns": "^2.30.0", - "prop-types": "^15.7.2", - "react-onclickoutside": "^6.13.0", - "react-popper": "^2.3.0" - }, - "peerDependencies": { - "react": "^16.9.0 || ^17 || ^18", - "react-dom": "^16.9.0 || ^17 || ^18" - } - }, "node_modules/react-dom": { "version": "18.2.0", "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz", @@ -8235,11 +8193,6 @@ "react": "^18.2.0" } }, - "node_modules/react-fast-compare": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/react-fast-compare/-/react-fast-compare-3.2.2.tgz", - "integrity": "sha512-nsO+KSNgo1SbJqJEYRE9ERzo7YtYbou/OqjSQKxV7jcKox7+usiUVZOAC+XnDOABXggQTno0Y1CpVnuWEc1boQ==" - }, "node_modules/react-hot-toast": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/react-hot-toast/-/react-hot-toast-2.4.1.tgz", @@ -8261,33 +8214,6 @@ "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==", "dev": true }, - "node_modules/react-onclickoutside": { - "version": "6.13.0", - "resolved": "https://registry.npmjs.org/react-onclickoutside/-/react-onclickoutside-6.13.0.tgz", - "integrity": "sha512-ty8So6tcUpIb+ZE+1HAhbLROvAIJYyJe/1vRrrcmW+jLsaM+/powDRqxzo6hSh9CuRZGSL1Q8mvcF5WRD93a0A==", - "funding": { - "type": "individual", - "url": "https://github.com/Pomax/react-onclickoutside/blob/master/FUNDING.md" - }, - "peerDependencies": { - "react": "^15.5.x || ^16.x || ^17.x || ^18.x", - "react-dom": "^15.5.x || ^16.x || ^17.x || ^18.x" - } - }, - "node_modules/react-popper": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/react-popper/-/react-popper-2.3.0.tgz", - "integrity": "sha512-e1hj8lL3uM+sgSR4Lxzn5h1GxBlpa4CQz0XLF8kx4MDrDRWY0Ena4c97PUeSX9i5W3UAfDP0z0FXCTQkoXUl3Q==", - "dependencies": { - "react-fast-compare": "^3.0.1", - "warning": "^4.0.2" - }, - "peerDependencies": { - "@popperjs/core": "^2.0.0", - "react": "^16.8.0 || ^17 || ^18", - "react-dom": "^16.8.0 || ^17 || ^18" - } - }, "node_modules/react-ssr-prepass": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/react-ssr-prepass/-/react-ssr-prepass-1.5.0.tgz", @@ -9660,14 +9586,6 @@ "makeerror": "1.0.12" } }, - "node_modules/warning": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/warning/-/warning-4.0.3.tgz", - "integrity": "sha512-rpJyN222KWIvHJ/F53XSZv0Zl/accqHR8et1kpaMTD/fLCRxtV8iX8czMzY7sVZupTI3zcUTg8eycS2kNF9l6w==", - "dependencies": { - "loose-envify": "^1.0.0" - } - }, "node_modules/webidl-conversions": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", diff --git a/package.json b/package.json index 24200887..f4add015 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,6 @@ "qrcode.react": "^3.1.0", "react": "18.2.0", "react-copy-to-clipboard": "^5.1.0", - "react-datepicker": "^4.21.0", "react-dom": "18.2.0", "react-hot-toast": "^2.4.0", "react-timeago": "^7.1.0", @@ -107,4 +106,4 @@ "prisma": { "seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts" } -} \ No newline at end of file +} diff --git a/src/components/adminPage/users/table/accounts.tsx b/src/components/adminPage/users/table/accounts.tsx index ea309d1a..7be0b852 100644 --- a/src/components/adminPage/users/table/accounts.tsx +++ b/src/components/adminPage/users/table/accounts.tsx @@ -149,7 +149,7 @@ export const Accounts = () => { }`}

), - rootStyle: "text-left", + rootStyle: "text-left max-w-2xl ", content: , }) } diff --git a/src/components/adminPage/users/userIsActive.tsx b/src/components/adminPage/users/userIsActive.tsx index 236994d8..705efdec 100644 --- a/src/components/adminPage/users/userIsActive.tsx +++ b/src/components/adminPage/users/userIsActive.tsx @@ -1,10 +1,8 @@ import { User } from "@prisma/client"; import { useTranslations } from "next-intl"; -import React, { ForwardedRef, forwardRef, MouseEvent } from "react"; +import React, { useState } from "react"; import toast from "react-hot-toast"; import { api } from "~/utils/api"; -import DatePicker from "react-datepicker"; -import "react-datepicker/dist/react-datepicker.css"; import { useTrpcApiErrorHandler, useTrpcApiSuccessHandler, @@ -13,31 +11,13 @@ import { interface Iuser { user: Partial; } -const DateContainer = ({ children }) => { - return ( -
-
{children}
-
- ); -}; - -interface DateButtonProps { - value?: string | null; - onClick?: (event: MouseEvent) => void; -} - -const DateButton = forwardRef( - ({ value, onClick }, ref: ForwardedRef) => ( - <> - - - ), -); const UserIsActive = ({ user }: Iuser) => { const t = useTranslations("admin"); + const [manualDate, setManualDate] = useState( + user.expiresAt ? new Date(user.expiresAt).toISOString().substring(0, 10) : null, + ); + const [isEdited, setIsEdited] = useState(false); const handleApiError = useTrpcApiErrorHandler(); const handleApiSuccess = useTrpcApiSuccessHandler(); @@ -55,7 +35,46 @@ const UserIsActive = ({ user }: Iuser) => { onError: handleApiError, onSuccess: handleApiSuccess({ actions: [refetchUser, refetchUsers] }), }); - + const handleManualDateChange = (e: React.ChangeEvent) => { + setManualDate(e.target.value); + setIsEdited(true); + }; + const handleSaveDate = () => { + if (manualDate) { + const parsedDate = new Date(manualDate); + if (!Number.isNaN(parsedDate.getTime())) { + updateUser( + { + id: user?.id, + params: { expiresAt: parsedDate }, + }, + { + onSuccess: () => { + toast.success("User updated successfully"); + setIsEdited(false); + }, + }, + ); + } else { + toast.error("Invalid date format"); + } + } + }; + const handleResetDate = () => { + updateUser( + { + id: user?.id, + params: { expiresAt: null }, + }, + { + onSuccess: () => { + toast.success("User updated successfully"); + setManualDate(null); + setIsEdited(false); + }, + }, + ); + }; return (

@@ -91,48 +110,32 @@ const UserIsActive = ({ user }: Iuser) => {

{t("users.users.userOptionModal.account.userExpireLabel")}

-
- - updateUser( - { - id: user?.id, - params: { expiresAt: date }, - }, - { - onSuccess: () => { - toast.success("User updated successfully"); - }, - }, - ) - } - calendarContainer={DateContainer} - customInput={} +
+ { + e.target.type = "date"; + }} + aria-label="Date" + className="input input-bordered btn-sm" + placeholder="Never" + value={manualDate || ""} + onChange={handleManualDateChange} + style={{ + zIndex: 2, + backgroundColor: manualDate ? "inherit" : "transparent", + }} /> - {user.expiresAt ? ( - + )} + {user.expiresAt && !isEdited && ( + - ) : null} + )}