Skip to content

Commit

Permalink
Merge pull request #137 from sinamics/de_auth_warning
Browse files Browse the repository at this point in the history
Show modal when de-authorize a member
  • Loading branch information
sinamics authored Sep 10, 2023
2 parents 9e96331 + ea7188d commit 1d88c2a
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "UserOptions" ADD COLUMN "deAuthorizeWarning" BOOLEAN DEFAULT false;
3 changes: 3 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ model UserOptions {
// local controller
localControllerUrl String? @default("http://zerotier:9993")
localControllerSecret String? @default("")
// member table
deAuthorizeWarning Boolean? @default(false)
}

enum AccessLevel {
Expand Down
2 changes: 1 addition & 1 deletion src/components/modules/accountTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export const Accounts = () => {
</tbody>
</table>
<div className="flex flex-col items-center justify-between py-3 sm:flex-row">
<TableFooter table={table} />
<TableFooter table={table} page="accountTable" />
</div>
</div>
</div>
Expand Down
43 changes: 31 additions & 12 deletions src/components/modules/table/memberHeaderColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const sortingIpaddress = (
export const MemberHeaderColumns = ({ nwid, central = false }: IProp) => {
const t = useTranslations();
const { callModal } = useModalStore((state) => state);

const { data: me } = api.auth.me.useQuery();
const { data: networkById, refetch: refetchNetworkById } =
api.network.getNetworkById.useQuery(
{
Expand Down Expand Up @@ -107,17 +107,36 @@ export const MemberHeaderColumns = ({ nwid, central = false }: IProp) => {
<input
type="checkbox"
checked={getValue()}
onChange={(event) =>
updateMember(
{
nwid,
memberId: original.id,
central,
updateParams: { authorized: event.target.checked },
},
{ onSuccess: () => void refetchNetworkById() },
)
}
onChange={(event) => {
const authorized = event.target.checked;
if (me?.options?.deAuthorizeWarning && !authorized) {
callModal({
title: "Warning",
description: "Are you sure you want to deauthorize this member?",
yesAction: () => {
updateMember(
{
nwid,
memberId: original.id,
central,
updateParams: { authorized },
},
{ onSuccess: () => void refetchNetworkById() },
);
},
});
} else {
updateMember(
{
nwid,
memberId: original.id,
central,
updateParams: { authorized: event.target.checked },
},
{ onSuccess: () => void refetchNetworkById() },
);
}
}}
// className="checkbox-error checkbox"
className="checkbox-success checkbox checkbox-xs sm:checkbox-sm"
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/modules/tableFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const TableFooter = ({ table, page }: { table: Table<any>; page: string }) => {
{t("show")} {pageSize}
</option>
))}
<option value="all">Show All</option>
<option value="all">{t("show")} All</option>
</select>
</div>
<div className="space-x-3 p-2">
Expand Down
5 changes: 4 additions & 1 deletion src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,10 @@
"showMarkerInTable": "Show marker in Table",
"showMarkerInTableDescription": "This will add a circle before the the member name with the anotation color.<br></br>You can still search the anotation if disabled.",
"addBackgroundColorInTable": "Add background color in table",
"addBackgroundColorInTableDescription": "This will add row background color based on the anotation color.<br></br>You can still search the anotation if disabled."
"addBackgroundColorInTableDescription": "This will add row background color based on the anotation color.<br></br>You can still search the anotation if disabled.",
"memberTableTitle": "Member Table",
"deAuthorizationWarningTitle": "Display warning on member De-Authorization",
"deAuthorizationWarningLabel": "Display a confirmation modal to prevent accidental de-authorizations."
},
"zerotierCentral": {
"title": "Zerotier Central",
Expand Down
5 changes: 4 additions & 1 deletion src/locales/es/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,10 @@
"showMarkerInTable": "Mostrar marcador en la tabla",
"showMarkerInTableDescription": "Esto agregará un círculo antes del nombre del miembro con el color de la anotación. <br></br> Todavía puedes buscar la anotación si está desactivada.",
"addBackgroundColorInTable": "Agregar color de fondo en la tabla",
"addBackgroundColorInTableDescription": "Esto agregará color de fondo a la fila según el color de la anotación. <br></br> Todavía puedes buscar la anotación si está desactivada."
"addBackgroundColorInTableDescription": "Esto agregará color de fondo a la fila según el color de la anotación. <br></br> Todavía puedes buscar la anotación si está desactivada.",
"memberTableTitle": "Tabla de Miembros",
"deAuthorizationWarningTitle": "Mostrar advertencia al desautorizar a un miembro",
"deAuthorizationWarningLabel": "Mostrar un modal de confirmación para evitar desautorizaciones accidentales."
},
"zerotierCentral": {
"title": "Zerotier Central",
Expand Down
5 changes: 4 additions & 1 deletion src/locales/no/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,10 @@
"showMarkerInTable": "Vis markør i tabellen",
"showMarkerInTableDescription": "Dette vil legge til en sirkel før medlemsnavnet med anmerkningsfargen. <br></br> Du kan fremdeles søke anmerkningen hvis deaktivert.",
"addBackgroundColorInTable": "Legg til bakgrunnsfarge i tabellen",
"addBackgroundColorInTableDescription": "Dette vil legge til radbakgrunnsfarge basert på anmerkningsfargen. <br></br> Du kan fremdeles søke anmerkningen hvis deaktivert."
"addBackgroundColorInTableDescription": "Dette vil legge til radbakgrunnsfarge basert på anmerkningsfargen. <br></br> Du kan fremdeles søke anmerkningen hvis deaktivert.",
"memberTableTitle": "Medlems Liste",
"deAuthorizationWarningTitle": "Vis advarsel ved fjerning av medlemsautorisasjon",
"deAuthorizationWarningLabel": "Vis en bekreftelsesmodal for å forhindre utilsiktet fjerning av autorisasjoner."
},
"zerotierCentral": {
"title": "Zerotier Central",
Expand Down
5 changes: 4 additions & 1 deletion src/locales/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,10 @@
"showMarkerInTable": "在表格中显示标记",
"showMarkerInTableDescription": "这将在成员名称前添加一个带有注释颜色的圆圈。<br></br>如果禁用,您仍然可以搜索注释。",
"addBackgroundColorInTable": "在表格中添加背景颜色",
"addBackgroundColorInTableDescription": "这将根据注释颜色添加行背景颜色。<br></br>如果禁用,您仍然可以搜索注释。"
"addBackgroundColorInTableDescription": "这将根据注释颜色添加行背景颜色。<br></br>如果禁用,您仍然可以搜索注释。",
"memberTableTitle": "成员表格",
"deAuthorizationWarningTitle": "在取消成员授权时显示警告",
"deAuthorizationWarningLabel": "显示确认模态框以防止意外取消授权。"
},
"zerotierCentral": {
"title": "Zerotier Central",
Expand Down
36 changes: 33 additions & 3 deletions src/pages/user-settings/network/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { useTranslations } from "use-intl";

const UserNetworkSetting = () => {
const t = useTranslations("userSettings");
const { mutate: updateNotation } = api.auth.updateUserNotation.useMutation();
const { mutate: updateSettings } = api.auth.updateUserOptions.useMutation();

const { data: me, refetch: refetchMe } = api.auth.me.useQuery();

return (
Expand All @@ -29,7 +30,7 @@ const UserNetworkSetting = () => {
checked={me?.options?.showNotationMarkerInTableRow || false}
className="checkbox-primary checkbox checkbox-sm justify-self-end"
onChange={(e) => {
updateNotation(
updateSettings(
{
showNotationMarkerInTableRow: e.target.checked,
},
Expand All @@ -54,7 +55,7 @@ const UserNetworkSetting = () => {
checked={me?.options?.useNotationColorAsBg || false}
className="checkbox-primary checkbox checkbox-sm justify-self-end"
onChange={(e) => {
updateNotation(
updateSettings(
{
useNotationColorAsBg: e.target.checked,
},
Expand All @@ -64,6 +65,35 @@ const UserNetworkSetting = () => {
/>
</div>
</div>
<div className="pb-10">
<p className="text-sm text-gray-400">
{t("account.networkSetting.memberTableTitle")}
</p>
<div className="divider mt-0 p-0 text-gray-500"></div>
<div className="flex justify-between py-2">
<div>
<p className="font-medium">
{t("account.networkSetting.deAuthorizationWarningTitle")}
</p>
<p className="text-sm text-gray-500">
{t("account.networkSetting.deAuthorizationWarningLabel")}
</p>
</div>
<input
type="checkbox"
checked={me?.options?.deAuthorizeWarning || false}
className="checkbox-primary checkbox checkbox-sm justify-self-end"
onChange={(e) => {
updateSettings(
{
deAuthorizeWarning: e.target.checked,
},
{ onSuccess: () => void refetchMe() },
);
}}
/>
</div>
</div>
</main>
);
};
Expand Down
17 changes: 5 additions & 12 deletions src/server/api/routers/authRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,29 +464,22 @@ export const authRouter = createTRPCRouter({
* - showMarkerInTable: an optional boolean that determines whether to show a marker in the table for the notation
* @returns A Promise that resolves with the updated NetworkMemberNotation instance.
*/
updateUserNotation: protectedProcedure
updateUserOptions: protectedProcedure
.input(
z.object({
useNotationColorAsBg: z.boolean().optional(),
showNotationMarkerInTableRow: z.boolean().optional(),
deAuthorizeWarning: z.boolean().optional(),
}),
)
.mutation(async ({ ctx, input }) => {
return await ctx.prisma.user.update({
where: {
id: ctx.session.user.id,
},
where: { id: ctx.session.user.id },
data: {
options: {
upsert: {
create: {
useNotationColorAsBg: input.useNotationColorAsBg,
showNotationMarkerInTableRow: input.showNotationMarkerInTableRow,
},
update: {
useNotationColorAsBg: input.useNotationColorAsBg,
showNotationMarkerInTableRow: input.showNotationMarkerInTableRow,
},
create: input,
update: input,
},
},
},
Expand Down

0 comments on commit 1d88c2a

Please sign in to comment.