refactor(web): redesign Settings components (#5237)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Johnny 2025-11-08 10:32:55 +08:00 committed by GitHub
parent 805bb4e741
commit c54fcf7aa7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 829 additions and 680 deletions

View file

@ -1,5 +1,5 @@
import copy from "copy-to-clipboard";
import { ClipboardIcon, TrashIcon } from "lucide-react";
import { ClipboardIcon, PlusIcon, TrashIcon } from "lucide-react";
import { useEffect, useState } from "react";
import { toast } from "react-hot-toast";
import ConfirmDialog from "@/components/ConfirmDialog";
@ -10,6 +10,7 @@ import { useDialog } from "@/hooks/useDialog";
import { UserAccessToken } from "@/types/proto/api/v1/user_service";
import { useTranslate } from "@/utils/i18n";
import CreateAccessTokenDialog from "../CreateAccessTokenDialog";
import SettingTable from "./SettingTable";
const listAccessTokens = async (parent: string) => {
const { accessTokens } = await userServiceClient.listUserAccessTokens({ parent });
@ -63,78 +64,63 @@ const AccessTokenSection = () => {
};
return (
<div className="mt-6 w-full flex flex-col justify-start items-start space-y-4">
<div className="w-full">
<div className="sm:flex sm:items-center sm:justify-between">
<div className="sm:flex-auto space-y-1">
<p className="flex flex-row justify-start items-center font-medium text-muted-foreground">
{t("setting.access-token-section.title")}
</p>
<p className="text-sm text-muted-foreground">{t("setting.access-token-section.description")}</p>
<div className="w-full flex flex-col gap-2">
<div className="flex flex-col sm:flex-row sm:items-start sm:justify-between gap-2">
<div className="flex flex-col gap-1">
<h4 className="text-sm font-medium text-muted-foreground">{t("setting.access-token-section.title")}</h4>
<p className="text-xs text-muted-foreground">{t("setting.access-token-section.description")}</p>
</div>
<div className="mt-4 sm:mt-0">
<Button color="primary" onClick={handleCreateToken}>
<Button onClick={handleCreateToken} size="sm">
<PlusIcon className="w-4 h-4 mr-1.5" />
{t("common.create")}
</Button>
</div>
</div>
<div className="w-full mt-2 flow-root">
<div className="overflow-x-auto">
<div className="inline-block min-w-full border border-border rounded-lg align-middle">
<table className="min-w-full divide-y divide-border">
<thead>
<tr>
<th scope="col" className="px-3 py-2 text-left text-sm font-semibold text-foreground">
{t("setting.access-token-section.token")}
</th>
<th scope="col" className="py-2 pl-4 pr-3 text-left text-sm font-semibold text-foreground">
{t("common.description")}
</th>
<th scope="col" className="px-3 py-2 text-left text-sm font-semibold text-foreground">
{t("setting.access-token-section.create-dialog.created-at")}
</th>
<th scope="col" className="px-3 py-2 text-left text-sm font-semibold text-foreground">
{t("setting.access-token-section.create-dialog.expires-at")}
</th>
<th scope="col" className="relative py-3.5 pl-3 pr-4">
<span className="sr-only">{t("common.delete")}</span>
</th>
</tr>
</thead>
<tbody className="divide-y divide-border">
{userAccessTokens.map((userAccessToken) => (
<tr key={userAccessToken.accessToken}>
<td className="whitespace-nowrap px-3 py-2 text-sm text-foreground flex flex-row justify-start items-center gap-x-1">
<span className="font-mono">{getFormatedAccessToken(userAccessToken.accessToken)}</span>
<Button variant="ghost" onClick={() => copyAccessToken(userAccessToken.accessToken)}>
<SettingTable
columns={[
{
key: "accessToken",
header: t("setting.access-token-section.token"),
render: (_, token: UserAccessToken) => (
<div className="flex items-center gap-1">
<span className="font-mono text-foreground">{getFormatedAccessToken(token.accessToken)}</span>
<Button variant="ghost" size="sm" onClick={() => copyAccessToken(token.accessToken)}>
<ClipboardIcon className="w-4 h-auto text-muted-foreground" />
</Button>
</td>
<td className="whitespace-nowrap py-2 pl-4 pr-3 text-sm text-foreground">{userAccessToken.description}</td>
<td className="whitespace-nowrap px-3 py-2 text-sm text-muted-foreground">
{userAccessToken.issuedAt?.toLocaleString()}
</td>
<td className="whitespace-nowrap px-3 py-2 text-sm text-muted-foreground">
{userAccessToken.expiresAt?.toLocaleString() ?? t("setting.access-token-section.create-dialog.duration-never")}
</td>
<td className="relative whitespace-nowrap py-2 pl-3 pr-4 text-right text-sm">
<Button
variant="ghost"
onClick={() => {
handleDeleteAccessToken(userAccessToken);
}}
>
</div>
),
},
{
key: "description",
header: t("common.description"),
render: (_, token: UserAccessToken) => <span className="text-foreground">{token.description}</span>,
},
{
key: "issuedAt",
header: t("setting.access-token-section.create-dialog.created-at"),
render: (_, token: UserAccessToken) => token.issuedAt?.toLocaleString(),
},
{
key: "expiresAt",
header: t("setting.access-token-section.create-dialog.expires-at"),
render: (_, token: UserAccessToken) =>
token.expiresAt?.toLocaleString() ?? t("setting.access-token-section.create-dialog.duration-never"),
},
{
key: "actions",
header: "",
className: "text-right",
render: (_, token: UserAccessToken) => (
<Button variant="ghost" size="sm" onClick={() => handleDeleteAccessToken(token)}>
<TrashIcon className="text-destructive w-4 h-auto" />
</Button>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
</div>
</div>
),
},
]}
data={userAccessTokens}
emptyMessage="No access tokens found"
getRowKey={(token) => token.name}
/>
{/* Create Access Token Dialog */}
<CreateAccessTokenDialog

View file

@ -4,7 +4,6 @@ import { useEffect, useState } from "react";
import { toast } from "react-hot-toast";
import { Button } from "@/components/ui/button";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { Separator } from "@/components/ui/separator";
import { Switch } from "@/components/ui/switch";
import { Textarea } from "@/components/ui/textarea";
import { identityProviderServiceClient } from "@/grpcweb";
@ -16,6 +15,9 @@ import { InstanceSetting_GeneralSetting, InstanceSetting_Key } from "@/types/pro
import { useTranslate } from "@/utils/i18n";
import ThemeSelect from "../ThemeSelect";
import UpdateCustomizedProfileDialog from "../UpdateCustomizedProfileDialog";
import SettingGroup from "./SettingGroup";
import SettingRow from "./SettingRow";
import SettingSection from "./SettingSection";
const InstanceSection = observer(() => {
const t = useTranslate();
@ -67,30 +69,25 @@ const InstanceSection = observer(() => {
};
return (
<div className="w-full flex flex-col gap-2 pt-2 pb-4">
<p className="font-medium text-foreground">{t("common.basic")}</p>
<div className="w-full flex flex-row justify-between items-center">
<div>
{t("setting.system-section.server-name")}:{" "}
<span className="font-mono font-bold">{instanceGeneralSetting.customProfile?.title || "Memos"}</span>
</div>
<SettingSection>
<SettingGroup title={t("common.basic")}>
<SettingRow label={t("setting.system-section.server-name")} description={instanceGeneralSetting.customProfile?.title || "Memos"}>
<Button variant="outline" onClick={handleUpdateCustomizedProfileButtonClick}>
{t("common.edit")}
</Button>
</div>
<Separator />
<p className="font-medium text-foreground">{t("setting.system-section.title")}</p>
<div className="w-full flex flex-row justify-between items-center">
<span>Theme</span>
</SettingRow>
</SettingGroup>
<SettingGroup title={t("setting.system-section.title")} showSeparator>
<SettingRow label="Theme">
<ThemeSelect
value={instanceGeneralSetting.theme || "default"}
onValueChange={(value: string) => updatePartialSetting({ theme: value })}
className="min-w-fit"
/>
</div>
<div className="w-full flex flex-row justify-between items-center">
<span>{t("setting.system-section.additional-style")}</span>
</div>
</SettingRow>
<SettingRow label={t("setting.system-section.additional-style")} vertical>
<Textarea
className="font-mono w-full"
rows={3}
@ -98,9 +95,9 @@ const InstanceSection = observer(() => {
value={instanceGeneralSetting.additionalStyle}
onChange={(event) => updatePartialSetting({ additionalStyle: event.target.value })}
/>
<div className="w-full flex flex-row justify-between items-center">
<span>{t("setting.system-section.additional-script")}</span>
</div>
</SettingRow>
<SettingRow label={t("setting.system-section.additional-script")} vertical>
<Textarea
className="font-mono w-full"
rows={3}
@ -108,16 +105,19 @@ const InstanceSection = observer(() => {
value={instanceGeneralSetting.additionalScript}
onChange={(event) => updatePartialSetting({ additionalScript: event.target.value })}
/>
<div className="w-full flex flex-row justify-between items-center">
<span>{t("setting.instance-section.disallow-user-registration")}</span>
</SettingRow>
</SettingGroup>
<SettingGroup title={t("setting.instance-section.disallow-user-registration")} showSeparator>
<SettingRow label={t("setting.instance-section.disallow-user-registration")}>
<Switch
disabled={instanceStore.state.profile.mode === "demo"}
checked={instanceGeneralSetting.disallowUserRegistration}
onCheckedChange={(checked) => updatePartialSetting({ disallowUserRegistration: checked })}
/>
</div>
<div className="w-full flex flex-row justify-between items-center">
<span>{t("setting.instance-section.disallow-password-auth")}</span>
</SettingRow>
<SettingRow label={t("setting.instance-section.disallow-password-auth")}>
<Switch
disabled={
instanceStore.state.profile.mode === "demo" ||
@ -126,23 +126,23 @@ const InstanceSection = observer(() => {
checked={instanceGeneralSetting.disallowPasswordAuth}
onCheckedChange={(checked) => updatePartialSetting({ disallowPasswordAuth: checked })}
/>
</div>
<div className="w-full flex flex-row justify-between items-center">
<span>{t("setting.instance-section.disallow-change-username")}</span>
</SettingRow>
<SettingRow label={t("setting.instance-section.disallow-change-username")}>
<Switch
checked={instanceGeneralSetting.disallowChangeUsername}
onCheckedChange={(checked) => updatePartialSetting({ disallowChangeUsername: checked })}
/>
</div>
<div className="w-full flex flex-row justify-between items-center">
<span>{t("setting.instance-section.disallow-change-nickname")}</span>
</SettingRow>
<SettingRow label={t("setting.instance-section.disallow-change-nickname")}>
<Switch
checked={instanceGeneralSetting.disallowChangeNickname}
onCheckedChange={(checked) => updatePartialSetting({ disallowChangeNickname: checked })}
/>
</div>
<div className="w-full flex flex-row justify-between items-center">
<span className="truncate">{t("setting.instance-section.week-start-day")}</span>
</SettingRow>
<SettingRow label={t("setting.instance-section.week-start-day")}>
<Select
value={instanceGeneralSetting.weekStartDayOffset.toString()}
onValueChange={(value) => {
@ -158,8 +158,10 @@ const InstanceSection = observer(() => {
<SelectItem value="1">{t("setting.instance-section.monday")}</SelectItem>
</SelectContent>
</Select>
</div>
<div className="mt-2 w-full flex justify-end">
</SettingRow>
</SettingGroup>
<div className="w-full flex justify-end">
<Button disabled={isEqual(instanceGeneralSetting, originalSetting)} onClick={handleSaveGeneralSetting}>
{t("common.save")}
</Button>
@ -173,7 +175,7 @@ const InstanceSection = observer(() => {
toast.success("Profile updated successfully!");
}}
/>
</div>
</SettingSection>
);
});

View file

@ -14,6 +14,8 @@ import { User, User_Role } from "@/types/proto/api/v1/user_service";
import { useTranslate } from "@/utils/i18n";
import CreateUserDialog from "../CreateUserDialog";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "../ui/dropdown-menu";
import SettingSection from "./SettingSection";
import SettingTable from "./SettingTable";
const MemberSection = observer(() => {
const t = useTranslate();
@ -101,54 +103,53 @@ const MemberSection = observer(() => {
};
return (
<div className="w-full flex flex-col gap-2 pt-2 pb-4">
<div className="w-full flex flex-row justify-between items-center">
<p className="font-medium text-muted-foreground">{t("setting.member-section.create-a-member")}</p>
<SettingSection
title={t("setting.member-list")}
actions={
<Button onClick={handleCreateUser}>
<PlusIcon className="w-4 h-4 mr-2" />
{t("common.create")}
</Button>
</div>
<div className="w-full flex flex-row justify-between items-center mt-6">
<div className="title-text">{t("setting.member-list")}</div>
</div>
<div className="w-full overflow-x-auto">
<div className="inline-block min-w-full align-middle border border-border rounded-lg">
<table className="min-w-full divide-y divide-border">
<thead>
<tr className="text-sm font-semibold text-left text-foreground">
<th scope="col" className="px-3 py-2">
{t("common.username")}
</th>
<th scope="col" className="px-3 py-2">
{t("common.role")}
</th>
<th scope="col" className="px-3 py-2">
{t("common.nickname")}
</th>
<th scope="col" className="px-3 py-2">
{t("common.email")}
</th>
<th scope="col" className="relative py-2 pl-3 pr-4"></th>
</tr>
</thead>
<tbody className="divide-y divide-border">
{sortedUsers.map((user) => (
<tr key={user.name}>
<td className="whitespace-nowrap px-3 py-2 text-sm text-muted-foreground">
}
>
<SettingTable
columns={[
{
key: "username",
header: t("common.username"),
render: (_, user: User) => (
<span className="text-foreground">
{user.username}
<span className="ml-1 italic">{user.state === State.ARCHIVED && "(Archived)"}</span>
</td>
<td className="whitespace-nowrap px-3 py-2 text-sm text-muted-foreground">{stringifyUserRole(user.role)}</td>
<td className="whitespace-nowrap px-3 py-2 text-sm text-muted-foreground">{user.displayName}</td>
<td className="whitespace-nowrap px-3 py-2 text-sm text-muted-foreground">{user.email}</td>
<td className="relative whitespace-nowrap py-2 pl-3 pr-4 text-right text-sm font-medium flex justify-end">
{currentUser?.name === user.name ? (
<span>{t("common.yourself")}</span>
{user.state === State.ARCHIVED && <span className="ml-2 italic text-muted-foreground">(Archived)</span>}
</span>
),
},
{
key: "role",
header: t("common.role"),
render: (_, user: User) => stringifyUserRole(user.role),
},
{
key: "displayName",
header: t("common.nickname"),
render: (_, user: User) => user.displayName,
},
{
key: "email",
header: t("common.email"),
render: (_, user: User) => user.email,
},
{
key: "actions",
header: "",
className: "text-right",
render: (_, user: User) =>
currentUser?.name === user.name ? (
<span className="text-muted-foreground">{t("common.yourself")}</span>
) : (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline">
<Button variant="outline" size="sm">
<MoreVerticalIcon className="w-4 h-auto" />
</Button>
</DropdownMenuTrigger>
@ -161,24 +162,20 @@ const MemberSection = observer(() => {
) : (
<>
<DropdownMenuItem onClick={() => handleRestoreUserClick(user)}>{t("common.restore")}</DropdownMenuItem>
<DropdownMenuItem
onClick={() => handleDeleteUserClick(user)}
className="text-destructive focus:text-destructive"
>
<DropdownMenuItem onClick={() => handleDeleteUserClick(user)} className="text-destructive focus:text-destructive">
{t("setting.member-section.delete-member")}
</DropdownMenuItem>
</>
)}
</DropdownMenuContent>
</DropdownMenu>
)}
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
),
},
]}
data={sortedUsers}
emptyMessage="No members found"
getRowKey={(user) => user.name}
/>
{/* Create User Dialog */}
<CreateUserDialog open={createDialog.isOpen} onOpenChange={createDialog.setOpen} onSuccess={fetchUsers} />
@ -207,7 +204,7 @@ const MemberSection = observer(() => {
onConfirm={confirmDeleteUser}
confirmVariant="destructive"
/>
</div>
</SettingSection>
);
});

View file

@ -11,6 +11,9 @@ import { instanceStore } from "@/store";
import { instanceSettingNamePrefix } from "@/store/common";
import { InstanceSetting_MemoRelatedSetting, InstanceSetting_Key } from "@/types/proto/api/v1/instance_service";
import { useTranslate } from "@/utils/i18n";
import SettingGroup from "./SettingGroup";
import SettingRow from "./SettingRow";
import SettingSection from "./SettingSection";
const MemoRelatedSettings = observer(() => {
const t = useTranslate();
@ -65,122 +68,125 @@ const MemoRelatedSettings = observer(() => {
};
return (
<div className="w-full flex flex-col gap-2 pt-2 pb-4">
<p className="font-medium text-muted-foreground">{t("setting.memo-related-settings.title")}</p>
<div className="w-full flex flex-row justify-between items-center">
<span>{t("setting.system-section.disable-public-memos")}</span>
<SettingSection>
<SettingGroup title={t("setting.memo-related-settings.title")}>
<SettingRow label={t("setting.system-section.disable-public-memos")}>
<Switch
checked={memoRelatedSetting.disallowPublicVisibility}
onCheckedChange={(checked) => updatePartialSetting({ disallowPublicVisibility: checked })}
/>
</div>
<div className="w-full flex flex-row justify-between items-center">
<span>{t("setting.system-section.display-with-updated-time")}</span>
</SettingRow>
<SettingRow label={t("setting.system-section.display-with-updated-time")}>
<Switch
checked={memoRelatedSetting.displayWithUpdateTime}
onCheckedChange={(checked) => updatePartialSetting({ displayWithUpdateTime: checked })}
/>
</div>
<div className="w-full flex flex-row justify-between items-center">
<span>{t("setting.memo-related-settings.enable-link-preview")}</span>
</SettingRow>
<SettingRow label={t("setting.memo-related-settings.enable-link-preview")}>
<Switch
checked={memoRelatedSetting.enableLinkPreview}
onCheckedChange={(checked) => updatePartialSetting({ enableLinkPreview: checked })}
/>
</div>
<div className="w-full flex flex-row justify-between items-center">
<span>{t("setting.system-section.enable-double-click-to-edit")}</span>
</SettingRow>
<SettingRow label={t("setting.system-section.enable-double-click-to-edit")}>
<Switch
checked={memoRelatedSetting.enableDoubleClickEdit}
onCheckedChange={(checked) => updatePartialSetting({ enableDoubleClickEdit: checked })}
/>
</div>
<div className="w-full flex flex-row justify-between items-center">
<span>{t("setting.system-section.disable-markdown-shortcuts-in-editor")}</span>
</SettingRow>
<SettingRow label={t("setting.system-section.disable-markdown-shortcuts-in-editor")}>
<Switch
checked={memoRelatedSetting.disableMarkdownShortcuts}
onCheckedChange={(checked) => updatePartialSetting({ disableMarkdownShortcuts: checked })}
/>
</div>
<div className="w-full flex flex-row justify-between items-center">
<span>{t("setting.memo-related-settings.content-lenght-limit")}</span>
</SettingRow>
<SettingRow label={t("setting.memo-related-settings.content-lenght-limit")}>
<Input
className="w-24"
type="number"
defaultValue={memoRelatedSetting.contentLengthLimit}
onBlur={(event) => updatePartialSetting({ contentLengthLimit: Number(event.target.value) })}
/>
</div>
<div className="w-full">
<span className="truncate">{t("setting.memo-related-settings.reactions")}</span>
<div className="mt-2 w-full flex flex-row flex-wrap gap-1">
{memoRelatedSetting.reactions.map((reactionType) => {
return (
<Badge key={reactionType} variant="outline" className="flex items-center gap-1 h-8">
</SettingRow>
</SettingGroup>
<SettingGroup title={t("setting.memo-related-settings.reactions")} showSeparator>
<div className="w-full flex flex-row flex-wrap gap-2">
{memoRelatedSetting.reactions.map((reactionType) => (
<Badge key={reactionType} variant="outline" className="flex items-center gap-1.5 h-8 px-3">
{reactionType}
<span
className="cursor-pointer text-muted-foreground hover:text-primary"
className="cursor-pointer text-muted-foreground hover:text-destructive"
onClick={() => updatePartialSetting({ reactions: memoRelatedSetting.reactions.filter((r) => r !== reactionType) })}
>
<X className="w-4 h-4" />
<X className="w-3.5 h-3.5" />
</span>
</Badge>
);
})}
<div className="flex items-center gap-1">
))}
<div className="flex items-center gap-1.5">
<Input
className="w-32"
className="w-32 h-8"
placeholder={t("common.input")}
value={editingReaction}
onChange={(event) => setEditingReaction(event.target.value.trim())}
onKeyDown={(e) => e.key === "Enter" && upsertReaction()}
/>
<span className="text-muted-foreground cursor-pointer hover:text-primary" onClick={() => upsertReaction()}>
<CheckIcon className="w-5 h-5" />
</span>
<Button variant="ghost" size="sm" onClick={upsertReaction} className="h-8 w-8 p-0">
<CheckIcon className="w-4 h-4" />
</Button>
</div>
</div>
</div>
<div className="w-full">
<div className="w-full flex flex-row justify-between items-center">
<span>{t("setting.memo-related-settings.enable-blur-nsfw-content")}</span>
</SettingGroup>
<SettingGroup showSeparator>
<SettingRow label={t("setting.memo-related-settings.enable-blur-nsfw-content")}>
<Switch
checked={memoRelatedSetting.enableBlurNsfwContent}
onCheckedChange={(checked) => updatePartialSetting({ enableBlurNsfwContent: checked })}
/>
</div>
<div className="mt-2 w-full flex flex-row flex-wrap gap-1">
{memoRelatedSetting.nsfwTags.map((nsfwTag) => {
return (
<Badge key={nsfwTag} variant="outline" className="flex items-center gap-1 h-8">
</SettingRow>
<div className="w-full flex flex-col gap-2">
<span className="text-sm text-muted-foreground">NSFW Tags</span>
<div className="w-full flex flex-row flex-wrap gap-2">
{memoRelatedSetting.nsfwTags.map((nsfwTag) => (
<Badge key={nsfwTag} variant="outline" className="flex items-center gap-1.5 h-8 px-3">
{nsfwTag}
<span
className="cursor-pointer text-muted-foreground hover:text-primary"
className="cursor-pointer text-muted-foreground hover:text-destructive"
onClick={() => updatePartialSetting({ nsfwTags: memoRelatedSetting.nsfwTags.filter((r) => r !== nsfwTag) })}
>
<X className="w-4 h-4" />
<X className="w-3.5 h-3.5" />
</span>
</Badge>
);
})}
<div className="flex items-center gap-1">
))}
<div className="flex items-center gap-1.5">
<Input
className="w-32"
className="w-32 h-8"
placeholder={t("common.input")}
value={editingNsfwTag}
onChange={(event) => setEditingNsfwTag(event.target.value.trim())}
onKeyDown={(e) => e.key === "Enter" && upsertNsfwTags()}
/>
<span className="text-muted-foreground cursor-pointer hover:text-primary" onClick={() => upsertNsfwTags()}>
<CheckIcon className="w-5 h-5" />
</span>
<Button variant="ghost" size="sm" onClick={upsertNsfwTags} className="h-8 w-8 p-0">
<CheckIcon className="w-4 h-4" />
</Button>
</div>
</div>
</div>
<div className="mt-2 w-full flex justify-end">
</SettingGroup>
<div className="w-full flex justify-end">
<Button disabled={isEqual(memoRelatedSetting, originalSetting)} onClick={updateSetting}>
{t("common.save")}
</Button>
</div>
</div>
</SettingSection>
);
});

View file

@ -8,6 +8,8 @@ import UpdateAccountDialog from "../UpdateAccountDialog";
import UserAvatar from "../UserAvatar";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "../ui/dropdown-menu";
import AccessTokenSection from "./AccessTokenSection";
import SettingGroup from "./SettingGroup";
import SettingSection from "./SettingSection";
import UserSessionsSection from "./UserSessionsSection";
const MyAccountSection = () => {
@ -25,44 +27,50 @@ const MyAccountSection = () => {
};
return (
<div className="w-full gap-2 pt-2 pb-4">
<p className="font-medium text-muted-foreground">{t("setting.account-section.title")}</p>
<div className="w-full mt-2 flex flex-row justify-start items-center">
<UserAvatar className="mr-2 shrink-0 w-10 h-10" avatarUrl={user.avatarUrl} />
<div className="max-w-[calc(100%-3rem)] flex flex-col justify-center items-start">
<p className="w-full">
<span className="text-xl leading-tight font-medium">{user.displayName}</span>
<span className="ml-1 text-base leading-tight text-muted-foreground">({user.username})</span>
</p>
<p className="w-4/5 leading-tight text-sm truncate">{user.description}</p>
<SettingSection>
<SettingGroup title={t("setting.account-section.title")}>
<div className="w-full flex flex-row justify-start items-center gap-3">
<UserAvatar className="shrink-0 w-12 h-12" avatarUrl={user.avatarUrl} />
<div className="flex-1 min-w-0 flex flex-col justify-center items-start gap-1">
<div className="w-full">
<span className="text-lg font-semibold">{user.displayName}</span>
<span className="ml-2 text-sm text-muted-foreground">@{user.username}</span>
</div>
{user.description && <p className="w-full text-sm text-muted-foreground truncate">{user.description}</p>}
</div>
<div className="w-full flex flex-row justify-start items-center mt-2 space-x-2">
<Button variant="outline" onClick={handleEditAccount}>
<PenLineIcon className="w-4 h-4 mx-auto mr-1" />
<div className="flex items-center gap-2 shrink-0">
<Button variant="outline" size="sm" onClick={handleEditAccount}>
<PenLineIcon className="w-4 h-4 mr-1.5" />
{t("common.edit")}
</Button>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline">
<MoreVerticalIcon className="w-4 h-4 mx-auto" />
<Button variant="outline" size="sm">
<MoreVerticalIcon className="w-4 h-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="start">
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={handleChangePassword}>{t("setting.account-section.change-password")}</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</div>
</SettingGroup>
<SettingGroup showSeparator>
<UserSessionsSection />
</SettingGroup>
<SettingGroup showSeparator>
<AccessTokenSection />
</SettingGroup>
{/* Update Account Dialog */}
<UpdateAccountDialog open={accountDialog.isOpen} onOpenChange={accountDialog.setOpen} />
{/* Change Password Dialog */}
<ChangeMemberPasswordDialog open={passwordDialog.isOpen} onOpenChange={passwordDialog.setOpen} user={user} />
</div>
</SettingSection>
);
};

View file

@ -1,6 +1,5 @@
import { observer } from "mobx-react-lite";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { Separator } from "@/components/ui/separator";
import { userStore, instanceStore } from "@/store";
import { Visibility } from "@/types/proto/api/v1/memo_service";
import { UserSetting_GeneralSetting } from "@/types/proto/api/v1/user_service";
@ -9,6 +8,9 @@ import { convertVisibilityFromString, convertVisibilityToString } from "@/utils/
import LocaleSelect from "../LocaleSelect";
import ThemeSelect from "../ThemeSelect";
import VisibilityIcon from "../VisibilityIcon";
import SettingGroup from "./SettingGroup";
import SettingRow from "./SettingRow";
import SettingSection from "./SettingSection";
import WebhookSection from "./WebhookSection";
const PreferencesSection = observer(() => {
@ -41,23 +43,19 @@ const PreferencesSection = observer(() => {
};
return (
<div className="w-full flex flex-col gap-2 pt-2 pb-4">
<p className="font-medium text-muted-foreground">{t("common.basic")}</p>
<div className="w-full flex flex-row justify-between items-center">
<span>{t("common.language")}</span>
<SettingSection>
<SettingGroup title={t("common.basic")}>
<SettingRow label={t("common.language")}>
<LocaleSelect value={setting.locale} onChange={handleLocaleSelectChange} />
</div>
</SettingRow>
<div className="w-full flex flex-row justify-between items-center">
<span>{t("setting.preference-section.theme")}</span>
<SettingRow label={t("setting.preference-section.theme")}>
<ThemeSelect value={setting.theme} onValueChange={handleThemeChange} />
</div>
</SettingRow>
</SettingGroup>
<p className="font-medium text-muted-foreground">{t("setting.preference")}</p>
<div className="w-full flex flex-row justify-between items-center">
<span className="truncate">{t("setting.preference-section.default-memo-visibility")}</span>
<SettingGroup title={t("setting.preference")} showSeparator>
<SettingRow label={t("setting.preference-section.default-memo-visibility")}>
<Select value={setting.memoVisibility} onValueChange={handleDefaultMemoVisibilityChanged}>
<SelectTrigger className="min-w-fit">
<div className="flex items-center gap-2">
@ -75,12 +73,13 @@ const PreferencesSection = observer(() => {
))}
</SelectContent>
</Select>
</div>
<Separator className="my-3" />
</SettingRow>
</SettingGroup>
<SettingGroup showSeparator>
<WebhookSection />
</div>
</SettingGroup>
</SettingSection>
);
});

View file

@ -1,15 +1,16 @@
import { MoreVerticalIcon } from "lucide-react";
import { MoreVerticalIcon, PlusIcon } from "lucide-react";
import { useEffect, useState } from "react";
import { toast } from "react-hot-toast";
import ConfirmDialog from "@/components/ConfirmDialog";
import { Button } from "@/components/ui/button";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
import { Separator } from "@/components/ui/separator";
import { identityProviderServiceClient } from "@/grpcweb";
import { IdentityProvider } from "@/types/proto/api/v1/idp_service";
import { useTranslate } from "@/utils/i18n";
import CreateIdentityProviderDialog from "../CreateIdentityProviderDialog";
import LearnMore from "../LearnMore";
import SettingSection from "./SettingSection";
import SettingTable from "./SettingTable";
const SSOSection = () => {
const t = useTranslate();
@ -68,48 +69,60 @@ const SSOSection = () => {
};
return (
<div className="w-full flex flex-col gap-2 pt-2 pb-4">
<div className="w-full flex flex-row justify-between items-center gap-1">
<div className="flex flex-row items-center gap-1">
<span className="font-mono text-muted-foreground">{t("setting.sso-section.sso-list")}</span>
<SettingSection
title={
<div className="flex items-center gap-2">
<span>{t("setting.sso-section.sso-list")}</span>
<LearnMore url="https://www.usememos.com/docs/configuration/authentication" />
</div>
<Button color="primary" onClick={handleCreateIdentityProvider}>
}
actions={
<Button onClick={handleCreateIdentityProvider}>
<PlusIcon className="w-4 h-4 mr-2" />
{t("common.create")}
</Button>
</div>
<Separator />
{identityProviderList.map((identityProvider) => (
<div
key={identityProvider.name}
className="py-2 w-full border-b last:border-b border-border flex flex-row items-center justify-between"
}
>
<div className="flex flex-row items-center">
<p className="ml-2">
{identityProvider.title}
<span className="text-sm ml-1 text-muted-foreground">({identityProvider.type})</span>
</p>
</div>
<div className="flex flex-row items-center">
<SettingTable
columns={[
{
key: "title",
header: t("common.name"),
render: (_, provider: IdentityProvider) => (
<span className="text-foreground">
{provider.title}
<span className="ml-2 text-sm text-muted-foreground">({provider.type})</span>
</span>
),
},
{
key: "actions",
header: "",
className: "text-right",
render: (_, provider: IdentityProvider) => (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline">
<Button variant="outline" size="sm">
<MoreVerticalIcon className="w-4 h-auto" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" sideOffset={2}>
<DropdownMenuItem onClick={() => handleEditIdentityProvider(identityProvider)}>{t("common.edit")}</DropdownMenuItem>
<DropdownMenuItem onClick={() => handleDeleteIdentityProvider(identityProvider)}>{t("common.delete")}</DropdownMenuItem>
<DropdownMenuItem onClick={() => handleEditIdentityProvider(provider)}>{t("common.edit")}</DropdownMenuItem>
<DropdownMenuItem
onClick={() => handleDeleteIdentityProvider(provider)}
className="text-destructive focus:text-destructive"
>
{t("common.delete")}
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</div>
))}
{identityProviderList.length === 0 && (
<div className="w-full mt-2 text-sm border-border text-muted-foreground flex flex-row items-center justify-between">
<p className="">{t("setting.sso-section.no-sso-found")}</p>
</div>
)}
),
},
]}
data={identityProviderList}
emptyMessage={t("setting.sso-section.no-sso-found")}
getRowKey={(provider) => provider.name}
/>
<CreateIdentityProviderDialog
open={isCreateDialogOpen}
@ -127,7 +140,7 @@ const SSOSection = () => {
onConfirm={confirmDeleteIdentityProvider}
confirmVariant="destructive"
/>
</div>
</SettingSection>
);
};

View file

@ -0,0 +1,34 @@
import React from "react";
import { Separator } from "@/components/ui/separator";
import { cn } from "@/lib/utils";
interface SettingGroupProps {
title?: string;
description?: string;
children: React.ReactNode;
className?: string;
showSeparator?: boolean;
}
/**
* Groups related settings together with optional title and separator
* Use this to organize multiple SettingRows under a common category
*/
const SettingGroup: React.FC<SettingGroupProps> = ({ title, description, children, className, showSeparator = false }) => {
return (
<>
{showSeparator && <Separator className="my-2" />}
<div className={cn("flex flex-col gap-3", className)}>
{(title || description) && (
<div className="flex flex-col gap-1">
{title && <h4 className="text-sm font-medium text-muted-foreground">{title}</h4>}
{description && <p className="text-xs text-muted-foreground">{description}</p>}
</div>
)}
<div className="flex flex-col gap-3">{children}</div>
</div>
</>
);
};
export default SettingGroup;

View file

@ -0,0 +1,45 @@
import { HelpCircleIcon } from "lucide-react";
import React from "react";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
import { cn } from "@/lib/utils";
interface SettingRowProps {
label: string;
description?: string;
tooltip?: string;
children: React.ReactNode;
className?: string;
vertical?: boolean;
}
/**
* Standardized row component for individual settings
* Provides consistent label/control layout with optional tooltip
*/
const SettingRow: React.FC<SettingRowProps> = ({ label, description, tooltip, children, className, vertical = false }) => {
return (
<div className={cn("w-full flex gap-3", vertical ? "flex-col" : "flex-row justify-between items-center", className)}>
<div className={cn("flex flex-col gap-1", vertical ? "w-full" : "flex-1 min-w-0")}>
<div className="flex items-center gap-1.5">
<span className={cn("text-sm", vertical ? "font-medium" : "")}>{label}</span>
{tooltip && (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<HelpCircleIcon className="w-4 h-4 text-muted-foreground cursor-help" />
</TooltipTrigger>
<TooltipContent>
<p className="max-w-xs">{tooltip}</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
)}
</div>
{description && <p className="text-xs text-muted-foreground">{description}</p>}
</div>
<div className={cn("flex items-center", vertical ? "w-full" : "shrink-0")}>{children}</div>
</div>
);
};
export default SettingRow;

View file

@ -0,0 +1,35 @@
import React from "react";
import { cn } from "@/lib/utils";
interface SettingSectionProps {
title?: React.ReactNode;
description?: string;
children: React.ReactNode;
className?: string;
actions?: React.ReactNode;
}
/**
* Wrapper component for consistent section layout in settings pages
* Provides standardized spacing, titles, and descriptions
*/
const SettingSection: React.FC<SettingSectionProps> = ({ title, description, children, className, actions }) => {
return (
<div className={cn("w-full flex flex-col gap-4 pt-2 pb-4", className)}>
{(title || description || actions) && (
<div className="flex flex-col sm:flex-row sm:items-start sm:justify-between gap-2">
<div className="flex-1">
{title && (
<div className="text-base font-semibold text-foreground mb-1">{typeof title === "string" ? <h3>{title}</h3> : title}</div>
)}
{description && <p className="text-sm text-muted-foreground">{description}</p>}
</div>
{actions && <div className="flex items-center gap-2">{actions}</div>}
</div>
)}
<div className="flex flex-col gap-4">{children}</div>
</div>
);
};
export default SettingSection;

View file

@ -0,0 +1,69 @@
import React from "react";
import { cn } from "@/lib/utils";
interface SettingTableColumn {
key: string;
header: string;
className?: string;
render?: (value: any, row: any) => React.ReactNode;
}
interface SettingTableProps {
columns: SettingTableColumn[];
data: any[];
emptyMessage?: string;
className?: string;
getRowKey?: (row: any, index: number) => string;
}
/**
* Standardized table component for settings data lists
* Provides consistent styling for tables in settings pages
*/
const SettingTable: React.FC<SettingTableProps> = ({ columns, data, emptyMessage = "No data", className, getRowKey }) => {
return (
<div className={cn("w-full overflow-x-auto", className)}>
<div className="inline-block min-w-full align-middle border border-border rounded-lg">
<table className="min-w-full divide-y divide-border">
<thead>
<tr className="text-sm font-semibold text-left text-foreground">
{columns.map((column) => (
<th key={column.key} scope="col" className={cn("px-3 py-2", column.className)}>
{column.header}
</th>
))}
</tr>
</thead>
<tbody className="divide-y divide-border">
{data.length === 0 ? (
<tr>
<td colSpan={columns.length} className="px-3 py-4 text-center text-sm text-muted-foreground">
{emptyMessage}
</td>
</tr>
) : (
data.map((row, rowIndex) => {
const rowKey = getRowKey ? getRowKey(row, rowIndex) : rowIndex.toString();
return (
<tr key={rowKey}>
{columns.map((column) => {
const value = row[column.key];
const content = column.render ? column.render(value, row) : value;
return (
<td key={column.key} className={cn("whitespace-nowrap px-3 py-2 text-sm text-muted-foreground", column.className)}>
{content}
</td>
);
})}
</tr>
);
})
)}
</tbody>
</table>
</div>
</div>
);
};
export default SettingTable;

View file

@ -1,5 +1,4 @@
import { isEqual } from "lodash-es";
import { HelpCircleIcon } from "lucide-react";
import { observer } from "mobx-react-lite";
import React, { useEffect, useMemo, useState } from "react";
import { toast } from "react-hot-toast";
@ -8,7 +7,6 @@ import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
import { Switch } from "@/components/ui/switch";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
import { instanceStore } from "@/store";
import { instanceSettingNamePrefix } from "@/store/common";
import {
@ -18,6 +16,9 @@ import {
InstanceSetting_StorageSetting_StorageType,
} from "@/types/proto/api/v1/instance_service";
import { useTranslate } from "@/utils/i18n";
import SettingGroup from "./SettingGroup";
import SettingRow from "./SettingRow";
import SettingSection from "./SettingSection";
const StorageSection = observer(() => {
const t = useTranslate();
@ -131,8 +132,9 @@ const StorageSection = observer(() => {
};
return (
<div className="w-full flex flex-col gap-2 pt-2 pb-4">
<div className="font-medium text-muted-foreground">{t("setting.storage-section.current-storage")}</div>
<SettingSection>
<SettingGroup title={t("setting.storage-section.current-storage")}>
<div className="w-full">
<RadioGroup
value={instanceStorageSetting.storageType}
onValueChange={(value) => {
@ -153,85 +155,66 @@ const StorageSection = observer(() => {
<Label htmlFor="s3">S3</Label>
</div>
</RadioGroup>
<div className="w-full flex flex-row justify-between items-center">
<div className="flex flex-row items-center">
<span className="text-muted-foreground mr-1">{t("setting.system-section.max-upload-size")}</span>
<TooltipProvider>
<Tooltip>
<TooltipTrigger>
<HelpCircleIcon className="w-4 h-auto" />
</TooltipTrigger>
<TooltipContent>
<p>{t("setting.system-section.max-upload-size-hint")}</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
</div>
<Input className="w-16 font-mono" value={instanceStorageSetting.uploadSizeLimitMb} onChange={handleMaxUploadSizeChanged} />
</div>
<SettingRow label={t("setting.system-section.max-upload-size")} tooltip={t("setting.system-section.max-upload-size-hint")}>
<Input className="w-24 font-mono" value={instanceStorageSetting.uploadSizeLimitMb} onChange={handleMaxUploadSizeChanged} />
</SettingRow>
{instanceStorageSetting.storageType !== InstanceSetting_StorageSetting_StorageType.DATABASE && (
<div className="w-full flex flex-row justify-between items-center">
<span className="text-muted-foreground mr-1">{t("setting.storage-section.filepath-template")}</span>
<SettingRow label={t("setting.storage-section.filepath-template")}>
<Input
className="w-64"
value={instanceStorageSetting.filepathTemplate}
placeholder="assets/{timestamp}_{filename}"
onChange={handleFilepathTemplateChanged}
/>
</div>
</SettingRow>
)}
</SettingGroup>
{instanceStorageSetting.storageType === InstanceSetting_StorageSetting_StorageType.S3 && (
<>
<div className="w-full flex flex-row justify-between items-center">
<span className="text-muted-foreground mr-1">Access key id</span>
<Input
className="w-64"
value={instanceStorageSetting.s3Config?.accessKeyId}
placeholder=""
onChange={handleS3ConfigAccessKeyIdChanged}
/>
</div>
<div className="w-full flex flex-row justify-between items-center">
<span className="text-muted-foreground mr-1">Access key secret</span>
<SettingGroup title="S3 Configuration" showSeparator>
<SettingRow label="Access key id">
<Input className="w-64" value={instanceStorageSetting.s3Config?.accessKeyId} onChange={handleS3ConfigAccessKeyIdChanged} />
</SettingRow>
<SettingRow label="Access key secret">
<Input
className="w-64"
type="password"
value={instanceStorageSetting.s3Config?.accessKeySecret}
placeholder=""
onChange={handleS3ConfigAccessKeySecretChanged}
/>
</div>
<div className="w-full flex flex-row justify-between items-center">
<span className="text-muted-foreground mr-1">Endpoint</span>
<Input
className="w-64"
value={instanceStorageSetting.s3Config?.endpoint}
placeholder=""
onChange={handleS3ConfigEndpointChanged}
/>
</div>
<div className="w-full flex flex-row justify-between items-center">
<span className="text-muted-foreground mr-1">Region</span>
<Input className="w-64" value={instanceStorageSetting.s3Config?.region} placeholder="" onChange={handleS3ConfigRegionChanged} />
</div>
<div className="w-full flex flex-row justify-between items-center">
<span className="text-muted-foreground mr-1">Bucket</span>
<Input className="w-64" value={instanceStorageSetting.s3Config?.bucket} placeholder="" onChange={handleS3ConfigBucketChanged} />
</div>
<div className="w-full flex flex-row justify-between items-center">
<span className="text-muted-foreground mr-1">Use Path Style</span>
</SettingRow>
<SettingRow label="Endpoint">
<Input className="w-64" value={instanceStorageSetting.s3Config?.endpoint} onChange={handleS3ConfigEndpointChanged} />
</SettingRow>
<SettingRow label="Region">
<Input className="w-64" value={instanceStorageSetting.s3Config?.region} onChange={handleS3ConfigRegionChanged} />
</SettingRow>
<SettingRow label="Bucket">
<Input className="w-64" value={instanceStorageSetting.s3Config?.bucket} onChange={handleS3ConfigBucketChanged} />
</SettingRow>
<SettingRow label="Use Path Style">
<Switch
checked={instanceStorageSetting.s3Config?.usePathStyle}
onCheckedChange={(checked) => handleS3ConfigUsePathStyleChanged({ target: { checked } } as any)}
/>
</div>
</>
</SettingRow>
</SettingGroup>
)}
<div>
<div className="w-full flex justify-end">
<Button disabled={!allowSaveStorageSetting} onClick={saveInstanceStorageSetting}>
{t("common.save")}
</Button>
</div>
</div>
</SettingSection>
);
});

View file

@ -7,6 +7,7 @@ import { userServiceClient } from "@/grpcweb";
import useCurrentUser from "@/hooks/useCurrentUser";
import { UserSession } from "@/types/proto/api/v1/user_service";
import { useTranslate } from "@/utils/i18n";
import SettingTable from "./SettingTable";
const listUserSessions = async (parent: string) => {
const { sessions } = await userServiceClient.listUserSessions({ parent });
@ -71,87 +72,71 @@ const UserSessionsSection = () => {
};
return (
<div className="mt-6 w-full flex flex-col justify-start items-start space-y-4">
<div className="w-full">
<div className="sm:flex sm:items-center sm:justify-between">
<div className="sm:flex-auto space-y-1">
<p className="flex flex-row justify-start items-center font-medium text-muted-foreground">
{t("setting.user-sessions-section.title")}
</p>
<p className="text-sm text-muted-foreground">{t("setting.user-sessions-section.description")}</p>
<div className="w-full flex flex-col gap-2">
<div className="flex flex-col gap-1">
<h4 className="text-sm font-medium text-muted-foreground">{t("setting.user-sessions-section.title")}</h4>
<p className="text-xs text-muted-foreground">{t("setting.user-sessions-section.description")}</p>
</div>
</div>
<div className="w-full mt-2 flow-root">
<div className="overflow-x-auto">
<div className="inline-block min-w-full border border-border rounded-lg align-middle">
<table className="min-w-full divide-y divide-border">
<thead>
<tr>
<th scope="col" className="px-3 py-2 text-left text-sm font-semibold text-foreground">
{t("setting.user-sessions-section.device")}
</th>
<th scope="col" className="px-3 py-2 text-left text-sm font-semibold text-foreground">
{t("setting.user-sessions-section.last-active")}
</th>
<th scope="col" className="relative py-3.5 pl-3 pr-4">
<span className="sr-only">{t("common.delete")}</span>
</th>
</tr>
</thead>
<tbody className="divide-y divide-border">
{userSessions.map((userSession) => (
<tr key={userSession.sessionId}>
<td className="whitespace-nowrap px-3 py-2 text-sm text-foreground">
<SettingTable
columns={[
{
key: "device",
header: t("setting.user-sessions-section.device"),
render: (_, session: UserSession) => (
<div className="flex items-center space-x-3">
{getDeviceIcon(userSession.clientInfo?.deviceType || "")}
{getDeviceIcon(session.clientInfo?.deviceType || "")}
<div className="flex flex-col">
<span className="font-medium">
{formatDeviceInfo(userSession.clientInfo)}
{isCurrentSession(userSession) && (
<span className="font-medium text-foreground">
{formatDeviceInfo(session.clientInfo)}
{isCurrentSession(session) && (
<span className="ml-2 inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-primary/20 text-primary">
<WifiIcon className="w-3 h-3 mr-1" />
{t("setting.user-sessions-section.current")}
</span>
)}
</span>
<span className="text-xs text-muted-foreground font-mono">{getFormattedSessionId(userSession.sessionId)}</span>
<span className="text-xs text-muted-foreground font-mono">{getFormattedSessionId(session.sessionId)}</span>
</div>
</div>
</td>
<td className="whitespace-nowrap px-3 py-2 text-sm text-muted-foreground">
),
},
{
key: "lastAccessedTime",
header: t("setting.user-sessions-section.last-active"),
render: (_, session: UserSession) => (
<div className="flex items-center space-x-1">
<ClockIcon className="w-4 h-4" />
<span>{userSession.lastAccessedTime?.toLocaleString()}</span>
<span>{session.lastAccessedTime?.toLocaleString()}</span>
</div>
</td>
<td className="relative whitespace-nowrap py-2 pl-3 pr-4 text-right text-sm">
),
},
{
key: "actions",
header: "",
className: "text-right",
render: (_, session: UserSession) => (
<Button
variant="ghost"
disabled={isCurrentSession(userSession)}
onClick={() => {
handleRevokeSession(userSession);
}}
size="sm"
disabled={isCurrentSession(session)}
onClick={() => handleRevokeSession(session)}
title={
isCurrentSession(userSession)
isCurrentSession(session)
? t("setting.user-sessions-section.cannot-revoke-current")
: t("setting.user-sessions-section.revoke-session")
}
>
<TrashIcon
className={`w-4 h-auto ${isCurrentSession(userSession) ? "text-muted-foreground" : "text-destructive"}`}
/>
<TrashIcon className={`w-4 h-auto ${isCurrentSession(session) ? "text-muted-foreground" : "text-destructive"}`} />
</Button>
</td>
</tr>
))}
</tbody>
</table>
{userSessions.length === 0 && (
<div className="text-center py-8 text-muted-foreground">{t("setting.user-sessions-section.no-sessions")}</div>
)}
</div>
</div>
</div>
),
},
]}
data={userSessions}
emptyMessage={t("setting.user-sessions-section.no-sessions")}
getRowKey={(session) => session.sessionId}
/>
<ConfirmDialog
open={!!revokeTarget}
onOpenChange={(open) => !open && setRevokeTarget(undefined)}
@ -169,7 +154,6 @@ const UserSessionsSection = () => {
confirmVariant="destructive"
/>
</div>
</div>
);
};

View file

@ -1,4 +1,4 @@
import { ExternalLinkIcon, TrashIcon } from "lucide-react";
import { ExternalLinkIcon, PlusIcon, TrashIcon } from "lucide-react";
import { useEffect, useState } from "react";
import toast from "react-hot-toast";
import { Link } from "react-router-dom";
@ -9,6 +9,7 @@ import useCurrentUser from "@/hooks/useCurrentUser";
import { UserWebhook } from "@/types/proto/api/v1/user_service";
import { useTranslate } from "@/utils/i18n";
import CreateWebhookDialog from "../CreateWebhookDialog";
import SettingTable from "./SettingTable";
const WebhookSection = () => {
const t = useTranslate();
@ -52,71 +53,58 @@ const WebhookSection = () => {
};
return (
<div className="w-full flex flex-col justify-start items-start">
<div className="w-full flex justify-between items-center">
<div className="flex-auto space-y-1">
<p className="flex flex-row justify-start items-center font-medium text-muted-foreground">{t("setting.webhook-section.title")}</p>
</div>
<div>
<Button color="primary" onClick={() => setIsCreateWebhookDialogOpen(true)}>
<div className="w-full flex flex-col gap-2">
<div className="flex flex-col sm:flex-row sm:items-start sm:justify-between gap-2">
<h4 className="text-sm font-medium text-muted-foreground">{t("setting.webhook-section.title")}</h4>
<Button onClick={() => setIsCreateWebhookDialogOpen(true)} size="sm">
<PlusIcon className="w-4 h-4 mr-1.5" />
{t("common.create")}
</Button>
</div>
</div>
<div className="w-full mt-2 flow-root">
<div className="overflow-x-auto">
<div className="inline-block min-w-full border border-border rounded-lg align-middle">
<table className="min-w-full divide-y divide-border">
<thead>
<tr>
<th scope="col" className="px-3 py-2 text-left text-sm font-semibold text-foreground">
{t("common.name")}
</th>
<th scope="col" className="px-3 py-2 text-left text-sm font-semibold text-foreground">
{t("setting.webhook-section.url")}
</th>
<th scope="col" className="relative px-3 py-2 pr-4">
<span className="sr-only">{t("common.delete")}</span>
</th>
</tr>
</thead>
<tbody className="divide-y divide-border">
{webhooks.map((webhook) => (
<tr key={webhook.name}>
<td className="whitespace-nowrap px-3 py-2 text-sm text-foreground">{webhook.displayName}</td>
<td className="max-w-[200px] px-3 py-2 text-sm text-foreground truncate" title={webhook.url}>
<SettingTable
columns={[
{
key: "displayName",
header: t("common.name"),
render: (_, webhook: UserWebhook) => <span className="text-foreground">{webhook.displayName}</span>,
},
{
key: "url",
header: t("setting.webhook-section.url"),
render: (_, webhook: UserWebhook) => (
<span className="max-w-[300px] inline-block truncate text-foreground" title={webhook.url}>
{webhook.url}
</td>
<td className="relative whitespace-nowrap px-3 py-2 text-right text-sm">
<Button variant="ghost" onClick={() => handleDeleteWebhook(webhook)}>
</span>
),
},
{
key: "actions",
header: "",
className: "text-right",
render: (_, webhook: UserWebhook) => (
<Button variant="ghost" size="sm" onClick={() => handleDeleteWebhook(webhook)}>
<TrashIcon className="text-destructive w-4 h-auto" />
</Button>
</td>
</tr>
))}
),
},
]}
data={webhooks}
emptyMessage={t("setting.webhook-section.no-webhooks-found")}
getRowKey={(webhook) => webhook.name}
/>
{webhooks.length === 0 && (
<tr>
<td className="whitespace-nowrap px-3 py-2 text-sm text-foreground" colSpan={3}>
{t("setting.webhook-section.no-webhooks-found")}
</td>
</tr>
)}
</tbody>
</table>
</div>
</div>
</div>
<div className="w-full mt-2">
<div className="w-full">
<Link
className="text-muted-foreground text-sm inline-flex flex-row justify-start items-center hover:underline hover:text-primary"
className="text-muted-foreground text-sm inline-flex items-center hover:underline hover:text-primary"
to="https://www.usememos.com/docs/integrations/webhooks"
target="_blank"
>
{t("common.learn-more")}
<ExternalLinkIcon className="inline w-4 h-auto ml-1" />
<ExternalLinkIcon className="w-4 h-4 ml-1" />
</Link>
</div>
<CreateWebhookDialog
open={isCreateWebhookDialogOpen}
onOpenChange={setIsCreateWebhookDialogOpen}