+
+ You are going to delete
+ {policyName}. This might cause data loss, deleted trigger delivery policy cannot be
+ restored. Are you sure?
+
+
+ Please type {policyName} to proceed.
+
+
+ ) => setConfirmString(e.target.value)}
+ />
+
+
+ );
+};
+
+export default (): React.ReactElement => {
+ const [isDeletingPolicy, setIsDeletingPolicy] = useState(false);
+ const [isSourceVisible, setIsSourceVisible] = useState(true);
+ const [showDeleteModal, setShowDeleteModal] = useState(false);
+ const [deletionAlerts, deletionAlertsController] = useAlerts();
+ const astarte = useAstarte();
+ const navigate = useNavigate();
+ const { policyName = '' } = useParams();
+
+ const policyFetcher = useFetch(() => astarte.client.getTriggerDeliveryPolicy(policyName));
+
+ const checkData = (data: AstarteTriggerDeliveryPolicyDTO | null) => {
+ const newData: AstarteTriggerDeliveryPolicyDTO | null = data;
+ if (data?.event_ttl === null) {
+ delete newData?.event_ttl;
+ }
+ if (data?.retry_times === null || data?.retry_times === 0) {
+ delete newData?.retry_times;
+ }
+ return newData;
+ };
+
+ const handleToggleSourceVisibility = useCallback(() => {
+ setIsSourceVisible((isVisible) => !isVisible);
+ }, []);
+
+ const showConfirmDeleteModal = useCallback(() => {
+ setShowDeleteModal(true);
+ }, []);
+
+ const hideConfirmDeleteModal = useCallback(() => {
+ setShowDeleteModal(false);
+ }, []);
+
+ const handleConfirmDeletePolicy = useCallback(() => {
+ setIsDeletingPolicy(true);
+ astarte.client
+ .deleteTriggerDeliveryPolicy(policyName)
+ .then(() => {
+ navigate('/trigger-delivery-policies');
+ })
+ .catch((err) => {
+ deletionAlertsController.showError(
+ `Could not delete policy: ${parsedErrorMessage(err.response.status)}`,
+ );
+ setIsDeletingPolicy(false);
+ hideConfirmDeleteModal();
+ });
+ }, [astarte.client, policyName, navigate, deletionAlertsController, hideConfirmDeleteModal]);
+
+ return (
+