PHP 8.2.30
Preview: use-action.ts Size: 1.61 KB
//proc/thread-self/root/home/byroehnu/.trash/node_modules11/adminjs/src/frontend/hooks/use-action/use-action.ts

import { useNavigate, useLocation } from 'react-router'

import { ActionResponse } from '../../../backend/actions/action.interface.js'
import { ActionJSON, buildActionCallApiTrigger, buildActionClickHandler } from '../../interfaces/index.js'
import { DifferentActionParams, ActionCallCallback, UseActionResult } from './use-action.types.js'
import { actionHref } from '../../interfaces/action/action-href.js'
import { useActionResponseHandler } from './use-action-response-handler.js'
import { useTranslation } from '../use-translation.js'
import { useModal } from '../use-modal.js'

/**
 * @load ./use-action.doc.md
 * @subcategory Hooks
 *
 * @param {ActionJSON}   action      action object
 * @param {ActionParams} params
 * @param {ActionCallCallback} onActionCall - callback triggered when action is performed
 * @return {UseActionResult}
 * @class
 * @hideconstructor
 */
export function useAction<K extends ActionResponse>(
  action: ActionJSON,
  params: DifferentActionParams,
  onActionCall?: ActionCallCallback,
): UseActionResult<K> {
  const navigate = useNavigate()
  const location = useLocation()
  const translateFunctions = useTranslation()
  const modalFunctions = useModal()
  const actionResponseHandler = useActionResponseHandler(onActionCall)

  const href = actionHref(action, params)

  const callApi = buildActionCallApiTrigger<K>({
    action,
    params,
    actionResponseHandler,
  })

  const handleClick = buildActionClickHandler({
    action,
    params,
    actionResponseHandler,
    navigate,
    translateFunctions,
    modalFunctions,
    location,
  })

  return {
    href,
    callApi,
    handleClick,
  }
}

Directory Contents

Dirs: 0 × Files: 5

Name Size Perms Modified Actions
119 B lrw-r--r-- 2026-02-28 00:32:28
Edit Download
922 B lrw-r--r-- 2026-02-28 00:32:46
Edit Download
550 B lrw-r--r-- 2026-02-28 00:31:56
Edit Download
1.61 KB lrw-r--r-- 2026-02-28 00:32:46
Edit Download
1.19 KB lrw-r--r-- 2026-02-28 00:32:46
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).