github.com/minio/console@v1.4.1/web-app/src/screens/Console/Support/CallHome.tsx (about) 1 // This file is part of MinIO Console Server 2 // Copyright (c) 2023 MinIO, Inc. 3 // 4 // This program is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Affero General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Affero General Public License for more details. 13 // 14 // You should have received a copy of the GNU Affero General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17 import React, { Fragment, useEffect, useState } from "react"; 18 import { 19 Box, 20 Button, 21 CallHomeMenuIcon, 22 FormLayout, 23 HelpBox, 24 Loader, 25 PageLayout, 26 Switch, 27 } from "mds"; 28 import { Link, useNavigate } from "react-router-dom"; 29 import api from "../../../common/api"; 30 import { ErrorResponseHandler } from "../../../common/types"; 31 import { setErrorSnackMessage, setHelpName } from "../../../systemSlice"; 32 import { useAppDispatch } from "../../../store"; 33 import { ICallHomeResponse } from "./types"; 34 import { registeredCluster } from "../../../config"; 35 import CallHomeConfirmation from "./CallHomeConfirmation"; 36 import RegisterCluster from "./RegisterCluster"; 37 import PageHeaderWrapper from "../Common/PageHeaderWrapper/PageHeaderWrapper"; 38 import HelpMenu from "../HelpMenu"; 39 40 const CallHome = () => { 41 const dispatch = useAppDispatch(); 42 const navigate = useNavigate(); 43 44 const [loading, setLoading] = useState<boolean>(true); 45 const [showConfirmation, setShowConfirmation] = useState<boolean>(false); 46 const [diagEnabled, setDiagEnabled] = useState<boolean>(false); 47 const [oDiagEnabled, setODiagEnabled] = useState<boolean>(false); 48 const [oLogsEnabled, setOLogsEnabled] = useState<boolean>(false); 49 const [logsEnabled, setLogsEnabled] = useState<boolean>(false); 50 const [disableMode, setDisableMode] = useState<boolean>(false); 51 52 const clusterRegistered = registeredCluster(); 53 54 useEffect(() => { 55 if (loading) { 56 api 57 .invoke("GET", `/api/v1/support/callhome`) 58 .then((res: ICallHomeResponse) => { 59 setLoading(false); 60 61 setDiagEnabled(!!res.diagnosticsStatus); 62 setLogsEnabled(!!res.logsStatus); 63 64 setODiagEnabled(!!res.diagnosticsStatus); 65 setOLogsEnabled(!!res.logsStatus); 66 }) 67 .catch((err: ErrorResponseHandler) => { 68 setLoading(false); 69 dispatch(setErrorSnackMessage(err)); 70 }); 71 } 72 }, [loading, dispatch]); 73 74 const callHomeClose = (refresh: boolean) => { 75 if (refresh) { 76 setLoading(true); 77 } 78 setShowConfirmation(false); 79 }; 80 81 const confirmCallHomeAction = () => { 82 if (!clusterRegistered) { 83 navigate("/support/register"); 84 return; 85 } 86 setDisableMode(false); 87 setShowConfirmation(true); 88 }; 89 90 const disableCallHomeAction = () => { 91 setDisableMode(true); 92 setShowConfirmation(true); 93 }; 94 95 let mainVariant: "regular" | "callAction" = "regular"; 96 97 if ( 98 clusterRegistered && 99 (diagEnabled !== oDiagEnabled || logsEnabled !== oLogsEnabled) 100 ) { 101 mainVariant = "callAction"; 102 } 103 104 useEffect(() => { 105 dispatch(setHelpName("call_home")); 106 // eslint-disable-next-line react-hooks/exhaustive-deps 107 }, []); 108 109 return ( 110 <Fragment> 111 {showConfirmation && ( 112 <CallHomeConfirmation 113 onClose={callHomeClose} 114 open={showConfirmation} 115 logsStatus={logsEnabled} 116 diagStatus={diagEnabled} 117 disable={disableMode} 118 /> 119 )} 120 <PageHeaderWrapper label="Call Home" actions={<HelpMenu />} /> 121 <PageLayout> 122 {!clusterRegistered && <RegisterCluster compactMode />} 123 <FormLayout 124 helpBox={ 125 <HelpBox 126 title={"Learn more about Call Home"} 127 iconComponent={<CallHomeMenuIcon />} 128 help={ 129 <Fragment> 130 <Box 131 sx={{ 132 display: "flex", 133 flexFlow: "column", 134 fontSize: "14px", 135 flex: "2", 136 marginTop: "10px", 137 }} 138 > 139 <Box> 140 Enabling Call Home sends cluster health & status to your 141 registered MinIO Subscription Network account every 24 142 hours. 143 <br /> 144 <br /> 145 This helps the MinIO support team to provide quick 146 incident responses along with suggestions for possible 147 improvements that can be made to your MinIO instances. 148 <br /> 149 <br /> 150 Your cluster must be{" "} 151 <Link to={"/support/register"}>registered</Link> in the 152 MinIO Subscription Network (SUBNET) before enabling this 153 feature. 154 </Box> 155 </Box> 156 </Fragment> 157 } 158 /> 159 } 160 > 161 {loading ? ( 162 <span style={{ marginLeft: 5 }}> 163 <Loader style={{ width: 16, height: 16 }} /> 164 </span> 165 ) : ( 166 <Fragment> 167 <Switch 168 value="enableDiag" 169 id="enableDiag" 170 name="enableDiag" 171 checked={diagEnabled} 172 onChange={(event: React.ChangeEvent<HTMLInputElement>) => { 173 setDiagEnabled(event.target.checked); 174 }} 175 label={"Daily Health Report"} 176 disabled={!clusterRegistered} 177 description={ 178 "Daily Health Report enables you to proactively identify potential issues in your deployment before they escalate." 179 } 180 /> 181 <Switch 182 value="enableLogs" 183 id="enableLogs" 184 name="enableLogs" 185 checked={logsEnabled} 186 onChange={(event: React.ChangeEvent<HTMLInputElement>) => { 187 setLogsEnabled(event.target.checked); 188 }} 189 label={"Live Error Logs"} 190 disabled={!clusterRegistered} 191 description={ 192 "Live Error Logs will enable MinIO's support team and automatic diagnostics system to catch failures early." 193 } 194 /> 195 <Box 196 sx={{ 197 display: "flex", 198 alignItems: "center", 199 justifyContent: "flex-end", 200 marginTop: "55px", 201 gap: "0px 10px", 202 }} 203 > 204 {(oDiagEnabled || oLogsEnabled) && ( 205 <Button 206 id={"callhome-action"} 207 variant={"secondary"} 208 data-test-id="call-home-toggle-button" 209 onClick={disableCallHomeAction} 210 disabled={loading || !clusterRegistered} 211 > 212 Disable Call Home 213 </Button> 214 )} 215 <Button 216 id={"callhome-action"} 217 type="button" 218 variant={mainVariant} 219 data-test-id="call-home-toggle-button" 220 onClick={confirmCallHomeAction} 221 disabled={loading || !clusterRegistered} 222 > 223 Save Configuration 224 </Button> 225 </Box> 226 </Fragment> 227 )} 228 </FormLayout> 229 </PageLayout> 230 </Fragment> 231 ); 232 }; 233 234 export default CallHome;