Skip to content

Commit

Permalink
chore: update workspace setting section
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack committed Aug 28, 2024
1 parent a8ea280 commit 4e5810e
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions web/src/components/Settings/WorkspaceSection.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Button, Select, Textarea, Option, Divider } from "@mui/joy";
import { isEqual } from "lodash-es";
import { ExternalLinkIcon } from "lucide-react";
import { useState } from "react";
import { toast } from "react-hot-toast";
import { Link } from "react-router-dom";
import { workspaceSettingServiceClient } from "@/grpcweb";
import { workspaceSettingNamePrefix, useWorkspaceSettingStore } from "@/store/v1";
import { WorkspaceGeneralSetting } from "@/types/proto/api/v1/workspace_setting_service";
import { WorkspaceSettingKey } from "@/types/proto/store/workspace_setting";
Expand All @@ -13,9 +13,10 @@ import showUpdateCustomizedProfileDialog from "../UpdateCustomizedProfileDialog"
const WorkspaceSection = () => {
const t = useTranslate();
const workspaceSettingStore = useWorkspaceSettingStore();
const [workspaceGeneralSetting, setWorkspaceGeneralSetting] = useState<WorkspaceGeneralSetting>(
WorkspaceGeneralSetting.fromPartial(workspaceSettingStore.getWorkspaceSettingByKey(WorkspaceSettingKey.GENERAL)?.generalSetting || {}),
const originalSetting = WorkspaceGeneralSetting.fromPartial(
workspaceSettingStore.getWorkspaceSettingByKey(WorkspaceSettingKey.GENERAL)?.generalSetting || {},
);
const [workspaceGeneralSetting, setWorkspaceGeneralSetting] = useState<WorkspaceGeneralSetting>(originalSetting);

const handleUpdateCustomizedProfileButtonClick = () => {
showUpdateCustomizedProfileDialog();
Expand All @@ -35,11 +36,9 @@ const WorkspaceSection = () => {

const handleSaveGeneralSetting = async () => {
try {
await workspaceSettingServiceClient.setWorkspaceSetting({
setting: {
name: `${workspaceSettingNamePrefix}${WorkspaceSettingKey.GENERAL}`,
generalSetting: workspaceGeneralSetting,
},
await workspaceSettingStore.setWorkspaceSetting({
name: `${workspaceSettingNamePrefix}${WorkspaceSettingKey.GENERAL}`,
generalSetting: workspaceGeneralSetting,
});
} catch (error: any) {
toast.error(error.details);
Expand Down Expand Up @@ -118,8 +117,8 @@ const WorkspaceSection = () => {
<Option value={1}>Monday</Option>
</Select>
</div>
<div>
<Button variant="outlined" color="neutral" onClick={handleSaveGeneralSetting}>
<div className="mt-2 w-full flex justify-end">
<Button disabled={isEqual(workspaceGeneralSetting, originalSetting)} onClick={handleSaveGeneralSetting}>
{t("common.save")}
</Button>
</div>
Expand Down

0 comments on commit 4e5810e

Please sign in to comment.