fix: cleanup code in api keys

pull/2277/head
Agusti Fernandez Pardo 2022-04-14 18:38:55 +02:00
parent 128e36f489
commit 4142af7d92
4 changed files with 14 additions and 25 deletions

@ -1 +1 @@
Subproject commit a064983002b2b6dd288788c87eb8b218063af377
Subproject commit 1405f7a8615bfd0b7dab52bb994b7de6e6229519

View File

@ -19,20 +19,18 @@ import { TApiKeys } from "./ApiKeyListItem";
export default function ApiKeyDialogForm(props: {
title: string;
defaultValues?: TApiKeys;
defaultValues?: Omit<TApiKeys, "userId" | "createdAt" | "lastUsedAt">;
handleClose: () => void;
}) {
const { t } = useLocale();
const utils = trpc.useContext();
const [neverExpires, setNeverExpires] = useState(false);
const handleNoteChange = (e: { target: { value: string } }) => {
form.setValue("note", e.target.value);
};
const {
defaultValues = {
note: "" as string | undefined,
note: "",
expiresAt: dayjs().add(1, "month").toDate(),
} as Omit<TApiKeys, "userId" | "createdAt" | "lastUsedAt">,
},
} = props;
const [selectedDate, setSelectedDate] = useState(dayjs().add(1, "month").toDate());
@ -97,19 +95,14 @@ export default function ApiKeyDialogForm(props: {
</DialogFooter>
</>
) : (
<Form
<Form<Omit<TApiKeys, "userId" | "createdAt" | "lastUsedAt">>
form={form}
handleSubmit={async (event) => {
try {
const newApiKey = await utils.client.mutation("viewer.apiKeys.create", event);
setNewApiKey(newApiKey);
setNewApiKeyDetails({ ...event });
await utils.invalidateQueries(["viewer.apiKeys.list"]);
setSuccessfulNewApiKeyModal(true);
} catch (error: any) {
console.log(error);
showToast(error.message, "error");
}
const newApiKey = await utils.client.mutation("viewer.apiKeys.create", event);
setNewApiKey(newApiKey);
setNewApiKeyDetails({ ...event });
await utils.invalidateQueries(["viewer.apiKeys.list"]);
setSuccessfulNewApiKeyModal(true);
}}
className="space-y-4">
<div className=" mb-10 mt-1">
@ -121,7 +114,7 @@ export default function ApiKeyDialogForm(props: {
placeholder={t("personal_note_placeholder")}
{...form.register("note")}
type="text"
onChange={handleNoteChange}
// onChange={handleNoteChange}
/>
<div className="flex flex-col">

View File

@ -11,7 +11,6 @@ import { QueryCell } from "@lib/QueryCell";
import { trpc } from "@lib/trpc";
import { List } from "@components/List";
import Badge from "@components/ui/Badge";
export default function ApiKeyListContainer() {
const { t } = useLocale();
@ -27,10 +26,7 @@ export default function ApiKeyListContainer() {
<>
<div className="flex flex-row justify-between truncate pl-2 pr-1 ">
<div className="mt-9">
<div className="flex flex-row space-x-2">
<h2 className="font-cal text-lg font-medium leading-6 text-gray-900">{t("api_keys")}</h2>
<Badge variant="default">βeta</Badge>
</div>
<h2 className="font-cal text-lg font-medium leading-6 text-gray-900">{t("api_keys")}</h2>
<p className="mt-1 mb-5 text-sm text-gray-500">{t("api_keys_subtitle")}</p>
</div>
<div className="self-center">

View File

@ -90,7 +90,7 @@ export default function ApiKeyListItem(props: { apiKey: TApiKeys; onEditApiKey:
<ConfirmationDialogContent
variety="danger"
title={t("confirm_delete_api_key")}
confirmBtnText={t("revoke_token")}
confirmBtnText={t("revoke_api_key")}
cancelBtnText={t("cancel")}
onConfirm={() =>
deleteApiKey.mutate({