File size: 2,303 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import React, { ReactNode } from 'react'
import { InfoBox, MessageBox, Text } from '@adminjs/design-system'

import { useTranslation } from '../../hooks/index.js'

/**
 * @memberof ErrorMessageBox
 * @alias ErrorMessageBoxProps
 */
export type ErrorMessageBoxProps = {
  title: string;
  children: ReactNode;
  testId?: string;
}

/**
 * @class
 * Prints error message
 *
 * @component
 * @private
 * @example
 * return (
 * <ErrorMessageBox title={'Some error'}>
 *   <p>Text below the title</p>
 * </ErrorMessageBox>
 * )
 */
const ErrorMessageBox: React.FC<ErrorMessageBoxProps> = (props) => {
  const { children, title, testId } = props
  return (
    <MessageBox data-testid={testId} message={title}>
      <Text>
        {children}
      </Text>
    </MessageBox>
  )
}

const NoResourceError: React.FC<{ resourceId: string }> = (props) => {
  const { resourceId } = props
  const { translateMessage } = useTranslation()
  return (
    <InfoBox
      title={translateMessage('pageNotFound_title', resourceId, { resourceId })}
      illustration="NotFound"
      testId="NoResourceError"
    >
      <Text>
        {translateMessage('error404Resource', resourceId, { resourceId })}
      </Text>
    </InfoBox>
  )
}

const NoActionError: React.FC<{ resourceId: string; actionName: string }> = (props) => {
  const { resourceId, actionName } = props
  const { translateMessage } = useTranslation()
  return (
    <InfoBox
      title={translateMessage('pageNotFound_title', resourceId, { resourceId })}
      illustration="NotFound"
      testId="NoActionError"
    >
      <Text>
        {translateMessage('error404Action', resourceId, { resourceId, actionName })}
      </Text>
    </InfoBox>
  )
}

const NoRecordError: React.FC<{
  resourceId: string;
  recordId: string;
}> = (props) => {
  const { resourceId, recordId } = props
  const { translateMessage } = useTranslation()
  return (
    <InfoBox
      title={translateMessage('pageNotFound_title', resourceId, { resourceId })}
      illustration="NotFound"
      testId="NoRecordError"
    >
      <Text>
        {translateMessage('error404Record', resourceId, { resourceId, recordId })}
      </Text>
    </InfoBox>
  )
}

export {
  NoResourceError,
  NoActionError,
  NoRecordError,
  ErrorMessageBox,
  ErrorMessageBox as default,
}