Skip to content

Commit

Permalink
chore: further changes
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Jul 11, 2024
1 parent 70183e4 commit 2c73c47
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
1 change: 0 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"canvas-confetti": "^1.9.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"date-fns": "^3.6.0",
"dayjs": "^1.11.10",
"embla-carousel-react": "^8.0.2",
"gradient-avatar": "^1.0.2",
Expand Down
12 changes: 7 additions & 5 deletions frontend/src/components/ExpirySelect.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { format } from "date-fns";
import dayjs from "dayjs";
import { CalendarIcon } from "lucide-react";
import React from "react";
import { Calendar } from "src/components/ui/calendar";
Expand All @@ -14,9 +14,9 @@ const daysFromNow = (date?: Date) => {
if (!date) {
return 0;
}
return Math.ceil(
(new Date(date).getTime() - Date.now()) / (1000 * 60 * 60 * 24)
);
const now = dayjs();
const targetDate = dayjs(date);
return targetDate.diff(now, "day");
};

interface ExpiryProps {
Expand Down Expand Up @@ -66,7 +66,9 @@ const ExpirySelect: React.FC<ExpiryProps> = ({ value, onChange }) => {
>
<CalendarIcon className="mr-2 h-4 w-4" />
<span className="truncate">
{customExpiry && value ? format(value, "PPP") : "Custom..."}
{customExpiry && value
? dayjs(value).format("DD MMMM YYYY")
: "Custom..."}
</span>
</div>
</PopoverTrigger>
Expand Down
23 changes: 16 additions & 7 deletions frontend/src/components/Permissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,26 @@ const Permissions: React.FC<PermissionsProps> = ({
}) => {
const [permissions, setPermissions] = React.useState(initialPermissions);

const [canEditBudgetAmount, setCanEditBudgetAmount] = React.useState(
isNewConnection ? Number.isNaN(permissions.maxAmount) : canEditPermissions
);
const [canEditExpiry, setCanEditExpiry] = React.useState(
isNewConnection ? !permissions.expiresAt : canEditPermissions
);

// this is triggered when edit mode is cancelled in show app
React.useEffect(() => {
setPermissions(initialPermissions);
}, [initialPermissions]);
setCanEditBudgetAmount(
isNewConnection
? Number.isNaN(initialPermissions.maxAmount)
: canEditPermissions
);
setCanEditExpiry(
isNewConnection ? !initialPermissions.expiresAt : canEditPermissions
);
}, [canEditPermissions, initialPermissions, isNewConnection]);

const canEditBudgetAmount = isNewConnection
? Number.isNaN(permissions.maxAmount)
: canEditPermissions;
const canEditExpiry = isNewConnection
? !permissions.expiresAt
: canEditPermissions;
const [showBudgetOptions, setShowBudgetOptions] = React.useState(
isNewConnection ? !!permissions.maxAmount : true
);
Expand Down
5 changes: 0 additions & 5 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1845,11 +1845,6 @@ dargs@^8.0.0:
resolved "https://registry.yarnpkg.com/dargs/-/dargs-8.1.0.tgz#a34859ea509cbce45485e5aa356fef70bfcc7272"
integrity sha512-wAV9QHOsNbwnWdNW2FYvE1P56wtgSbM+3SZcdGiWQILwVjACCXDCI3Ai8QlCjMDB8YK5zySiXZYBiwGmNY3lnw==

date-fns@^3.6.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-3.6.0.tgz#f20ca4fe94f8b754951b24240676e8618c0206bf"
integrity sha512-fRHTG8g/Gif+kSh50gaGEdToemgfj74aRX3swtiouboip5JDLAyDE9F11nHMIcvOaXeOC6D7SpNhi7uFyB7Uww==

dayjs@^1.11.10:
version "1.11.10"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.10.tgz#68acea85317a6e164457d6d6947564029a6a16a0"
Expand Down

0 comments on commit 2c73c47

Please sign in to comment.