Skip to content

Commit

Permalink
Bug fix: apps with empty names are not updateable
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajat Saxena committed Feb 19, 2024
1 parent f1fdd18 commit 081715e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions apps/web/app/app/[keyid]/settings/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export async function updateAppName(
formData: FormData
) {
const newName = formData.get("newName") as string;
const name = formData.get("name") as string;
const keyId = formData.get("keyId") as string;
if (!newName) {
return { success: false, error: "Name is required" };
}
if (!name) {
if (!keyId) {
return { success: false, error: "Bad request" };
}

Expand All @@ -36,7 +36,7 @@ export async function updateAppName(
await ApikeyModel.updateOne(
{
userId: dbUser._id,
name,
keyId,
},
{ $set: { name: newName } }
);
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/app/[keyid]/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default async function Settings({
<CopyApikeyButton apikey={apikey.key} />
</div>
</div>
<UpdateSettingsForm name={apikey.name} />
<UpdateSettingsForm keyId={apikey.keyId} />
<Separator className="my-8" />
<DeleteAppButton apikey={apikey} />
</section>
Expand Down
8 changes: 4 additions & 4 deletions apps/web/app/app/[keyid]/settings/update-settings-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { useEffect, useState } from "react";
import { useRouter } from "next/navigation";
import { useToast } from "@/components/ui/use-toast";

export default function UpdateSettingsForm({ name }: { name: string }) {
export default function UpdateSettingsForm({ keyId }: { keyId: string }) {
const [state, updateNameAction] = useFormState(updateAppName, {
success: false,
});
const [newName, setNewName] = useState(name);
const [newName, setNewName] = useState("");
const router = useRouter();
const { toast } = useToast();

Expand All @@ -38,7 +38,7 @@ export default function UpdateSettingsForm({ name }: { name: string }) {

return (
<div>
<Label htmlFor="name" className="mb-2">
<Label htmlFor="newName" className="mb-2">
App name
</Label>
<form action={updateNameAction} className="flex gap-2">
Expand All @@ -47,7 +47,7 @@ export default function UpdateSettingsForm({ name }: { name: string }) {
value={newName}
onChange={(e) => setNewName(e.target.value)}
/>
<Input name="name" value={name} type="hidden" />
<Input name="keyId" value={keyId} type="hidden" />
<Submit>Save</Submit>
</form>
</div>
Expand Down

0 comments on commit 081715e

Please sign in to comment.