Skip to content
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions admin-ui/app/context/WebhookDialogContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Webhook Dialog Context
* Manages state for webhook trigger dialogs and error displays
* Replaces the deleted webhookReducer from Redux
*/

import React, { createContext, useContext } from 'react'
import type { WebhookEntry } from 'JansConfigApi'

export interface WebhookTriggerError {
success: boolean
responseMessage: string
responseObject: {
webhookId?: string
webhookName?: string
inum?: string
}
}

export interface WebhookDialogState {
showErrorModal: boolean
webhookModal: boolean
triggerWebhookMessage: string
webhookTriggerErrors: WebhookTriggerError[]
triggerWebhookInProgress: boolean
loadingWebhooks: boolean
featureWebhooks: WebhookEntry[]
featureToTrigger: string
}

export interface WebhookDialogActions {
setShowErrorModal: (show: boolean) => void
setWebhookModal: (show: boolean) => void
setTriggerWebhookResponse: (message: string) => void
setWebhookTriggerErrors: (errors: WebhookTriggerError[]) => void
setFeatureToTrigger: (feature: string) => void
setFeatureWebhooks: (webhooks: WebhookEntry[]) => void
setLoadingWebhooks: (loading: boolean) => void
setTriggerWebhookInProgress: (inProgress: boolean) => void
resetWebhookDialog: () => void
}

export interface WebhookDialogContextValue {
state: WebhookDialogState
actions: WebhookDialogActions
}

const WebhookDialogContext = createContext<WebhookDialogContextValue | undefined>(undefined)

export const useWebhookDialog = (): WebhookDialogContextValue => {
const context = useContext(WebhookDialogContext)
if (!context) {
throw new Error('useWebhookDialog must be used within a WebhookDialogProvider')
}
return context
}

export default WebhookDialogContext
83 changes: 83 additions & 0 deletions admin-ui/app/context/WebhookDialogProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* Webhook Dialog Provider
* Provides webhook dialog state and actions to the application
*/

import React, { useState, useMemo, useCallback } from 'react'
import WebhookDialogContext, {
type WebhookDialogState,
type WebhookDialogActions,
type WebhookDialogContextValue,
} from './WebhookDialogContext'
import type { WebhookEntry } from 'JansConfigApi'
import type { WebhookTriggerError } from './WebhookDialogContext'

const initialState: WebhookDialogState = {
showErrorModal: false,
webhookModal: false,
triggerWebhookMessage: '',
webhookTriggerErrors: [],
triggerWebhookInProgress: false,
loadingWebhooks: false,
featureWebhooks: [],
featureToTrigger: '',
}

export const WebhookDialogProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const [state, setState] = useState<WebhookDialogState>(initialState)

const actions: WebhookDialogActions = useMemo(
() => ({
setShowErrorModal: (show: boolean) => {
setState((prev) => ({ ...prev, showErrorModal: show }))
},

setWebhookModal: (show: boolean) => {
setState((prev) => ({ ...prev, webhookModal: show }))
},

setTriggerWebhookResponse: (message: string) => {
setState((prev) => ({ ...prev, triggerWebhookMessage: message }))
},

setWebhookTriggerErrors: (errors: WebhookTriggerError[]) => {
setState((prev) => ({ ...prev, webhookTriggerErrors: errors }))
},

setFeatureToTrigger: (feature: string) => {
setState((prev) => ({ ...prev, featureToTrigger: feature }))
},

setFeatureWebhooks: (webhooks: WebhookEntry[]) => {
setState((prev) => ({ ...prev, featureWebhooks: webhooks }))
},

setLoadingWebhooks: (loading: boolean) => {
setState((prev) => ({ ...prev, loadingWebhooks: loading }))
},

setTriggerWebhookInProgress: (inProgress: boolean) => {
setState((prev) => ({ ...prev, triggerWebhookInProgress: inProgress }))
},

resetWebhookDialog: () => {
setState(initialState)
},
}),
[],
)

const contextValue: WebhookDialogContextValue = useMemo(
() => ({
state,
actions,
}),
[state, actions],
)

return (
<WebhookDialogContext.Provider value={contextValue}>{children}</WebhookDialogContext.Provider>
)
}

export default WebhookDialogProvider
5 changes: 1 addition & 4 deletions admin-ui/app/context/theme/themeContext.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import React, { createContext, useReducer, Dispatch, ReactNode } from 'react'

// Define the shape of the theme state
type ThemeState = {
theme: string
}

// Define the shape of the actions for the reducer
type ThemeAction = {
type: string
}

// Define the context value type
interface ThemeContextType {
export interface ThemeContextType {
state: ThemeState
dispatch: Dispatch<ThemeAction>
}
Expand Down
5 changes: 4 additions & 1 deletion admin-ui/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import i18n from './i18n'
import { ThemeProvider } from 'Context/theme/themeContext'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
import { WebhookDialogProvider } from './context/WebhookDialogProvider'
import './styles/index.css'
import 'bootstrap/dist/css/bootstrap.css'

Expand All @@ -27,7 +28,9 @@ root.render(
<QueryClientProvider client={queryClient}>
<I18nextProvider i18n={i18n}>
<ThemeProvider>
<App />
<WebhookDialogProvider>
<App />
</WebhookDialogProvider>
</ThemeProvider>
</I18nextProvider>
<ReactQueryDevtools initialIsOpen={false} />
Expand Down
14 changes: 13 additions & 1 deletion admin-ui/app/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,10 @@
"webhook_execution_information": "Webhook Execution Information",
"webhook_dialog_dec": "As part of the submission process, the system will automatically trigger the following associated webhooks to perform additional processing tasks.",
"add_webhook": "Add Webhook",
"webhook_trigger_success": "All webhooks triggered successfully.",
"webhook_trigger_error": "Something went wrong while triggering webhook.",
"webhook_trigger_failed": "Failed to trigger webhook.",
"webhook_trigger_invalid_data": "Cannot trigger webhook: invalid data provided.",
"permission_name_error": "Please ensure the permission name is at least 5 characters long.",
"role_name_error": "Please ensure the role name is at least 5 characters long.",
"error_message": "Error Message",
Expand All @@ -739,6 +743,7 @@
"request_body_error": "HTTP Request Body is required for selected HTTP Method",
"display_name_error": "Please enter display name.",
"url_error": "Please enter URL.",
"aui_feature_ids_error": "At least one Admin UI Feature must be selected.",
"session_timeout_error": "Session timeout must be at least 1 minute",
"session_timeout_required_error": "Session timeout is required",
"invalid_json_error": "Invalid JSON value.",
Expand Down Expand Up @@ -825,7 +830,13 @@
"user_updated_successfully": "User updated successfully",
"user_deleted_successfully": "User deleted successfully",
"password_changed_successfully": "Password changed successfully",
"device_deleted_successfully": "Device deleted successfully"
"device_deleted_successfully": "Device deleted successfully",
"bad_request": "Bad request",
"unauthorized": "Unauthorized",
"forbidden": "Forbidden",
"not_found": "Not found",
"conflict": "Conflict",
"server_error": "Server error"
},
"errors": {
"attribute_create_failed": "Error creating attribute",
Expand Down Expand Up @@ -875,6 +886,7 @@
"enter_property_key": "Enter the property key",
"enter_property_value": "Enter the property value",
"enter_header_key": "Enter header key",
"enter_header_value": "Enter header value",
"enter_key_value": "Enter key value",
"enter_source_value": "Enter the source value",
"enter_destination_value": "Enter the destination value",
Expand Down
14 changes: 13 additions & 1 deletion admin-ui/app/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,10 @@
"webhook_execution_information": "Información de Ejecución del Webhook",
"webhook_dialog_dec": "Como parte del proceso de envío, el sistema activará automáticamente los siguientes webhooks asociados para realizar tareas de procesamiento adicionales.",
"add_webhook": "Agregar Webhook",
"webhook_trigger_success": "Todos los webhooks se activaron correctamente.",
"webhook_trigger_error": "Algo salió mal al activar el webhook.",
"webhook_trigger_failed": "No se pudo activar el webhook.",
"webhook_trigger_invalid_data": "No se puede activar el webhook: datos no válidos proporcionados.",
"permission_name_error": "Asegúrese de que el nombre del permiso tenga al menos 5 caracteres.",
"role_name_error": "Asegúrese de que el nombre del rol tenga al menos 5 caracteres.",
"error_message": "Mensaje de Error",
Expand All @@ -739,6 +743,7 @@
"request_body_error": "El cuerpo de la solicitud HTTP es obligatorio para el método HTTP seleccionado",
"display_name_error": "Ingrese el nombre para mostrar.",
"url_error": "Ingrese la URL.",
"aui_feature_ids_error": "Debe seleccionarse al menos una Función de Interfaz de Administración.",
"session_timeout_error": "El tiempo de espera de sesión debe ser de al menos 1 minuto",
"session_timeout_required_error": "El tiempo de espera de sesión es obligatorio",
"invalid_json_error": "Valor JSON inválido.",
Expand Down Expand Up @@ -824,7 +829,13 @@
"user_updated_successfully": "Usuario actualizado exitosamente",
"user_deleted_successfully": "Usuario eliminado exitosamente",
"password_changed_successfully": "Contraseña cambiada exitosamente",
"device_deleted_successfully": "Dispositivo eliminado exitosamente"
"device_deleted_successfully": "Dispositivo eliminado exitosamente",
"bad_request": "Solicitud incorrecta",
"unauthorized": "No autorizado",
"forbidden": "Prohibido",
"not_found": "No encontrado",
"conflict": "Conflicto",
"server_error": "Error del servidor"
},
"errors": {
"attribute_create_failed": "Error al crear el atributo",
Expand Down Expand Up @@ -868,6 +879,7 @@
"enter_property_key": "Introduce la clave de la propiedad",
"enter_property_value": "Introduce el valor de la propiedad",
"enter_header_key": "Introduce la clave de cabecera",
"enter_header_value": "Introduce el valor de cabecera",
"enter_key_value": "Introduce el valor de la clave",
"enter_source_value": "Introduce el valor de origen",
"enter_destination_value": "Introduce el valor de destino",
Expand Down
14 changes: 13 additions & 1 deletion admin-ui/app/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,10 @@
"view_trust_relationshi_details": "Voir les détails de la relation de confiance",
"add_trust_relationship": "Ajouter une relation de confiance",
"add_webhook": "Ajouter un Webhook",
"webhook_trigger_success": "Tous les webhooks ont été déclenchés avec succès.",
"webhook_trigger_error": "Une erreur s'est produite lors du déclenchement du webhook.",
"webhook_trigger_failed": "Échec du déclenchement du webhook.",
"webhook_trigger_invalid_data": "Impossible de déclencher le webhook : données non valides fournies.",
"no_spaces": "ne doit pas contenir d'espaces",
"permission_name_error": "Veuillez vous assurer que le nom de la permission comporte au moins 5 caractères.",
"role_name_error": "Veuillez vous assurer que le nom du rôle comporte au moins 5 caractères.",
Expand Down Expand Up @@ -708,6 +712,7 @@
"http_method_error": "Veuillez sélectionner une méthode HTTP.",
"display_name_error": "Veuillez entrer un nom d'affichage.",
"url_error": "Veuillez entrer une URL.",
"aui_feature_ids_error": "Au moins une Fonctionnalité de l'Interface d'Administration doit être sélectionnée.",
"invalid_json_error": "Valeur JSON invalide.",
"action_commit_question": "Journal d'audit : vous souhaitez appliquer les modifications apportées sur cette page ?",
"licenseAuditLog": "Voulez-vous vraiment réinitialiser la licence existante ?",
Expand Down Expand Up @@ -762,7 +767,13 @@
"user_updated_successfully": "Utilisateur mis à jour avec succès",
"user_deleted_successfully": "Utilisateur supprimé avec succès",
"password_changed_successfully": "Mot de passe modifié avec succès",
"device_deleted_successfully": "Appareil supprimé avec succès"
"device_deleted_successfully": "Appareil supprimé avec succès",
"bad_request": "Mauvaise requête",
"unauthorized": "Non autorisé",
"forbidden": "Interdit",
"not_found": "Non trouvé",
"conflict": "Conflit",
"server_error": "Erreur du serveur"
},
"errors": {
"attribute_create_failed": "Erreur lors de la création de l'attribut",
Expand Down Expand Up @@ -807,6 +818,7 @@
"description": "Entrer la description",
"display_name": "Entrez le nom d'affichage",
"enter_header_key": "Entrer la clé d'en-tête",
"enter_header_value": "Entrer la valeur d'en-tête",
"enter_key_value": "Entrer la valeur de la clé",
"enable_ssl_communication": "Activer la communication SSL entre le serveur d'authentification et le serveur LDAP",
"enter_property_key": "Entrez la clé de propriété",
Expand Down
14 changes: 13 additions & 1 deletion admin-ui/app/locales/pt/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,14 @@
"select_message_provider_type": "Por favor, selecione o tipo de provedor de mensagens",
"new_role": "Novo papel",
"add_webhook": "Adicionar Webhook",
"webhook_trigger_success": "Todos os webhooks foram acionados com sucesso.",
"webhook_trigger_error": "Algo deu errado ao acionar o webhook.",
"webhook_trigger_failed": "Falha ao acionar o webhook.",
"webhook_trigger_invalid_data": "Não é possível acionar o webhook: dados inválidos fornecidos.",
"http_method_error": "Por favor, selecione um método HTTP.",
"display_name_error": "Por favor, insira um nome de exibição.",
"url_error": "Por favor, insira uma URL.",
"aui_feature_ids_error": "Pelo menos um Recurso da Interface de Administração deve ser selecionado.",
"invalid_json_error": "Valor JSON inválido.",
"license_api_not_enabled": "A API de licença não está habilitada para este aplicativo.",
"adding_new_permission": "Adicionando nova permissão",
Expand Down Expand Up @@ -757,7 +762,13 @@
"user_updated_successfully": "Usuário atualizado com sucesso",
"user_deleted_successfully": "Usuário excluído com sucesso",
"password_changed_successfully": "Senha alterada com sucesso",
"device_deleted_successfully": "Dispositivo excluído com sucesso"
"device_deleted_successfully": "Dispositivo excluído com sucesso",
"bad_request": "Solicitação inválida",
"unauthorized": "Não autorizado",
"forbidden": "Proibido",
"not_found": "Não encontrado",
"conflict": "Conflito",
"server_error": "Erro do servidor"
},
"errors": {
"attribute_create_failed": "Erro ao criar atributo",
Expand Down Expand Up @@ -797,6 +808,7 @@
"client_description": "Insira a descrição do cliente",
"client_name": "Insira o nome do cliente",
"enter_header_key": "Digite a chave do cabeçalho",
"enter_header_value": "Digite o valor do cabeçalho",
"enter_key_value": "Digite o valor da chave",
"request_body_error": "O corpo da solicitação HTTP é obrigatório para o método HTTP selecionado",
"description": "Digite a descrição",
Expand Down
6 changes: 3 additions & 3 deletions admin-ui/app/routes/Apps/Gluu/GluuCommitDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import { ThemeContext } from 'Context/theme/themeContext'
import PropTypes from 'prop-types'
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown'
import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp'
import { useSelector } from 'react-redux'
import useWebhookDialogAction from 'Utils/hooks/useWebhookDialogAction'
import { WEBHOOK_READ } from 'Utils/PermChecker'
import { useCedarling } from '@/cedarling'
import customColors from '@/customColors'
import { useWebhookDialog } from '@/context/WebhookDialogContext'

const USER_MESSAGE = 'user_action_message'

Expand All @@ -44,10 +44,10 @@ const GluuCommitDialog = ({
const [active, setActive] = useState(false)
const [isOpen, setIsOpen] = useState(null)
const [userMessage, setUserMessage] = useState('')
const { loadingWebhooks, webhookModal } = useSelector((state: any) => state.webhookReducer)
const { state: webhookState } = useWebhookDialog()
const { loadingWebhooks, webhookModal } = webhookState
const { webhookTriggerModal, onCloseModal } = useWebhookDialogAction({
feature,
modal,
})

const prevModalRef = useRef<boolean>(false)
Expand Down
Loading
Loading