Skip to content

Commit

Permalink
chore: changes
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Jul 4, 2024
1 parent 4976123 commit e7a8a20
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
17 changes: 9 additions & 8 deletions frontend/src/components/Permissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const Permissions: React.FC<PermissionsProps> = ({
handlePermissionsChange({ scopes });
};

const handleBudgetMaxAmountChange = (amount: string) => {
const handleBudgetMaxAmountChange = (amount: number) => {
handlePermissionsChange({ maxAmount: amount });
};

Expand Down Expand Up @@ -162,14 +162,12 @@ const Permissions: React.FC<PermissionsProps> = ({
key={budget}
onClick={() => {
setCustomBudget(false);
handleBudgetMaxAmountChange(
budgetOptions[budget].toString()
);
handleBudgetMaxAmountChange(budgetOptions[budget]);
}}
className={cn(
"cursor-pointer rounded text-nowrap border-2 text-center p-4 dark:text-white",
!customBudget &&
(permissions.maxAmount === ""
(Number.isNaN(permissions.maxAmount)
? 100000
: +permissions.maxAmount) == budgetOptions[budget]
? "border-primary"
Expand All @@ -183,7 +181,7 @@ const Permissions: React.FC<PermissionsProps> = ({
<div
onClick={() => {
setCustomBudget(true);
handleBudgetMaxAmountChange("");
handleBudgetMaxAmountChange(0);
}}
className={cn(
"cursor-pointer rounded border-2 text-center p-4 dark:text-white",
Expand All @@ -204,9 +202,9 @@ const Permissions: React.FC<PermissionsProps> = ({
type="number"
required
min={1}
value={permissions.maxAmount}
value={permissions.maxAmount || ""}
onChange={(e) => {
handleBudgetMaxAmountChange(e.target.value.trim());
handleBudgetMaxAmountChange(parseInt(e.target.value));
}}
/>
</div>
Expand Down Expand Up @@ -271,6 +269,9 @@ const Permissions: React.FC<PermissionsProps> = ({
<PopoverContent className="w-auto p-0">
<Calendar
mode="single"
disabled={{
before: new Date(),
}}
selected={permissions.expiresAt}
onSelect={(date?: Date) => {
if (daysFromNow(date) == 0) {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/screens/apps/NewApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const NewAppInternal = ({ capabilities }: NewAppInternalProps) => {

const [permissions, setPermissions] = useState<AppPermissions>({
scopes: initialScopes,
maxAmount: budgetMaxAmountParam,
maxAmount: parseInt(budgetMaxAmountParam),
budgetRenewal: validBudgetRenewals.includes(budgetRenewalParam)
? budgetRenewalParam
: "monthly",
Expand All @@ -189,7 +189,7 @@ const NewAppInternal = ({ capabilities }: NewAppInternalProps) => {
name: appName,
pubkey,
budgetRenewal: permissions.budgetRenewal,
maxAmount: parseInt(permissions.maxAmount),
maxAmount: permissions.maxAmount,
scopes: Array.from(permissions.scopes),
expiresAt: permissions.expiresAt?.toISOString(),
returnTo: returnTo,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export interface App {

export interface AppPermissions {
scopes: Set<Scope>;
maxAmount: string;
maxAmount: number;
budgetRenewal: BudgetRenewalType;
expiresAt?: Date;
}
Expand Down

0 comments on commit e7a8a20

Please sign in to comment.