Line data Source code
1 : /*
2 : * Copyright (C) 2020 Red Hat, Inc.
3 : * SPDX-License-Identifier: LGPL-2.1-or-later
4 : */
5 :
6 18 : import cockpit from 'cockpit';
7 18 : import React from 'react';
8 : import { Checkbox } from "@patternfly/react-core/dist/esm/components/Checkbox/index.js";
9 :
10 : import { show_modal_dialog } from "cockpit-components-dialog.jsx";
11 :
12 18 : const _ = cockpit.gettext;
13 :
14 1 : function DeleteAccountDialogBody({ state, change }) {
15 1 : const { delete_files } = state;
16 :
17 1 : return (
18 1 : <Checkbox id="account-confirm-delete-files"
19 1 : label={_("Delete files")}
20 0 : isChecked={delete_files} onChange={(_event, checked) => change("delete_files", checked)} />
21 : );
22 1 : }
23 :
24 1 : export function delete_account_dialog(account) {
25 1 : let dlg = null;
26 :
27 1 : const state = {
28 1 : delete_files: false
29 1 : };
30 :
31 0 : function change(field, value) {
32 0 : state[field] = value;
33 0 : update();
34 0 : }
35 :
36 1 : function update() {
37 1 : const props = {
38 1 : id: "account-confirm-delete-dialog",
39 1 : title: cockpit.format(_("Delete $0"), account.name),
40 1 : body: <DeleteAccountDialogBody state={state} change={change} />
41 1 : };
42 :
43 1 : const footer = {
44 1 : actions: [
45 1 : {
46 1 : caption: _("Delete"),
47 1 : style: "danger",
48 1 : clicked: () => {
49 1 : const prog = ["/usr/sbin/userdel"];
50 1 : if (state.delete_files)
51 0 : prog.push("-r");
52 1 : prog.push(account.name);
53 :
54 1 : return cockpit.spawn(prog, { superuser: "require", err: "message" })
55 1 : .then(function () {
56 1 : cockpit.location.go("/");
57 1 : });
58 1 : }
59 1 : }
60 1 : ]
61 1 : };
62 :
63 1 : if (!dlg)
64 0 : dlg = show_modal_dialog(props, footer);
65 0 : else {
66 0 : dlg.setProps(props);
67 0 : dlg.setFooterProps(footer);
68 0 : }
69 1 : }
70 :
71 1 : update();
72 1 : }
|