Skip to content

Commit

Permalink
feat: add permanent option in frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
medtaher123 committed Sep 24, 2024
1 parent d783895 commit dec568c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
32 changes: 31 additions & 1 deletion frontend/src/components/context-vars/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import { faAsterisk } from "@fortawesome/free-solid-svg-icons";
import AddIcon from "@mui/icons-material/Add";
import { Button, Grid, Paper } from "@mui/material";
import { Button, Grid, Paper, Switch } from "@mui/material";
import { GridColDef } from "@mui/x-data-grid";
import React from "react";
import { useTranslation } from "react-i18next";
Expand All @@ -24,6 +24,7 @@ import { renderHeader } from "@/app-components/tables/columns/renderHeader";
import { DataGrid } from "@/app-components/tables/DataGrid";
import { useDelete } from "@/hooks/crud/useDelete";
import { useFind } from "@/hooks/crud/useFind";
import { useUpdate } from "@/hooks/crud/useUpdate";
import { getDisplayDialogs, useDialog } from "@/hooks/useDialog";
import { useHasPermission } from "@/hooks/useHasPermission";
import { useSearch } from "@/hooks/useSearch";
Expand Down Expand Up @@ -52,6 +53,14 @@ export const ContextVars = () => {
params: searchPayload,
},
);
const { mutateAsync: updateContextVar } = useUpdate(EntityType.CONTEXT_VAR, {
onError: () => {
toast.error(t("message.internal_server_error"));
},
onSuccess() {
toast.success(t("message.success_save"));
},
});
const { mutateAsync: deleteContextVar } = useDelete(EntityType.CONTEXT_VAR, {
onError: () => {
toast.error(t("message.internal_server_error"));
Expand Down Expand Up @@ -87,6 +96,27 @@ export const ContextVars = () => {
renderHeader,
headerAlign: "left",
},
{
maxWidth: 120,
field: "permanent",
headerName: t("label.permanent"),
disableColumnMenu: true,
renderHeader,
headerAlign: "left",
renderCell: (params) => (
<Switch
checked={params.value}
color="primary"
inputProps={{ "aria-label": "primary checkbox" }}
onChange={() => {
updateContextVar({
id: params.row.id,
params: { permanent: !params.value },
});
}}
/>
),
},
{
maxWidth: 140,
field: "createdAt",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/i18n/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@
"assign_labels": "Assign labels",
"replacement_tokens": "Replacement Tokens",
"built_in": "Built-in",
"permanent": "Permanent",
"assign_to": "Takeover By",
"assigned_to": "Assigned To",
"user_first_name": "First Name",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/i18n/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@
"assign_labels": "Affecter des étiquettes",
"replacement_tokens": "Jetons de remplacement",
"built_in": "Intégré",
"permanent": "Permanent",
"assign_to": "Assigner à",
"assigned_to": "Assigné(e) à",
"user_first_name": "Prénom",
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/types/context-var.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import { IBaseSchema, IFormat, OmitPopulate } from "./base.types";
export interface IContextVarAttributes {
name: string;
label: string;
permanent: boolean;
}

export interface IContextVarStub
extends IBaseSchema,
OmitPopulate<IContextVarAttributes, EntityType.CONTEXT_VAR> {
name: string;
label: string;
permanent: boolean;
}

export interface IContextVar extends IContextVarStub, IFormat<Format.BASIC> {}
Expand Down

0 comments on commit dec568c

Please sign in to comment.