fix
This commit is contained in:
@@ -7,31 +7,48 @@ import { Button } from "@/components/ui/button";
|
||||
import { localeMap } from "@/types";
|
||||
import { enUS } from "date-fns/locale";
|
||||
import { format } from "date-fns";
|
||||
import { revokeConsent } from "@/actions/consents";
|
||||
import { useState } from "react";
|
||||
|
||||
interface Props {
|
||||
consents: Consent[] | null;
|
||||
consents: Consent[] | [];
|
||||
setConsents: (consents: Consent[]) => void;
|
||||
}
|
||||
|
||||
export default function Applications({ consents, setConsents }: Props) {
|
||||
const t = useTranslations("MePage.items.applications");
|
||||
const [list, setList] = useState(consents);
|
||||
|
||||
const locale = useLocale();
|
||||
const dateLocale = localeMap[locale as keyof typeof localeMap] ?? enUS;
|
||||
|
||||
const handleRevoke = async (clientId: string) => {
|
||||
const result = await revokeConsent(clientId);
|
||||
if (result.success) {
|
||||
const updated = list.filter(c => c.client_id !== clientId);
|
||||
setList(updated);
|
||||
setConsents(updated);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="w-full lg:max-w-sm flex flex-col gap-4">
|
||||
<h1 className="text-xl">{t("title")}</h1>
|
||||
|
||||
<div className="space-y-4">
|
||||
{consents?.map((consent) => (
|
||||
{list.map((consent) => (
|
||||
<Item key={consent.client_id}>
|
||||
<ItemContent>
|
||||
<ItemTitle>{consent.client_name}</ItemTitle>
|
||||
<ItemDescription>{t("authorized")} {format(consent.authorized_at, "PPP", { locale: dateLocale }) }</ItemDescription>
|
||||
<ItemDescription>{t("authorized")} {format(consent.authorized_at, "PPP", { locale: dateLocale })}</ItemDescription>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<Button disabled={!consent.isRevokable}>{t("revoke")}</Button>
|
||||
<Button
|
||||
disabled={!consent.isRevokable}
|
||||
onClick={() => handleRevoke(consent.client_id)}
|
||||
>
|
||||
{t("revoke")}
|
||||
</Button>
|
||||
</ItemActions>
|
||||
</Item>
|
||||
))}
|
||||
|
||||
@@ -42,7 +42,7 @@ export default function Profile({ user, setUser }: Props) {
|
||||
|
||||
if (response == null) setError(t("form.updateError"))
|
||||
else setUser(response)
|
||||
} catch (error) {
|
||||
} catch {
|
||||
setError(t("form.updateError"))
|
||||
}
|
||||
};
|
||||
|
||||
@@ -10,7 +10,7 @@ export default async function Me() {
|
||||
redirect("/api/auth/initiate");
|
||||
}
|
||||
|
||||
var consents = await getConsents();
|
||||
const consents = await getConsents();
|
||||
|
||||
return <MeComponent userData={user} consentsData={consents} />;
|
||||
}
|
||||
Reference in New Issue
Block a user