Passed
Push — feature/add-2fa-support ( 23e818...85b1f3 )
by Chris
24:19 queued 11:16
created

resources/assets/js/components/ApplicantSkills/SkillsInfoModal.tsx   A

Complexity

Total Complexity 5
Complexity/F 0

Size

Lines of Code 121
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 91
dl 0
loc 121
rs 10
c 0
b 0
f 0
wmc 5
mnd 5
bc 5
fnc 0
bpm 0
cpm 0
noi 0
1
/* eslint-disable camelcase, @typescript-eslint/camelcase */
2
import React from "react";
3
import ReactDOM from "react-dom";
4
import InfoModal from "../InfoModal";
5
6
interface SkillsInfoModalProps {
7
  /** HTML ID for modal attributes */
8
  id: string;
9
  /** Title that appears within the modal when open */
10
  title: string;
11
  /** Text displayed on the button that displays the modal */
12
  openText: string;
13
  /** Text displayed on the modal confirmation button */
14
  confirmText: string;
15
  /** Text displayed inside the modal */
16
  modalInfo: any;
17
}
18
19
const SkillsInfoModal: React.FunctionComponent<SkillsInfoModalProps> = ({
20
  id,
21
  title,
22
  openText,
23
  confirmText,
24
  modalInfo,
25
}): React.ReactElement => {
26
  const { subtext, example_lists } = modalInfo;
27
  return (
28
    <InfoModal
29
      id={id}
30
      title={title}
31
      openText={openText}
32
      confirmText={confirmText}
33
    >
34
      <div className="modal-info__wrapper">
35
        {Object.values(subtext).map(
36
          (item: string): React.ReactElement => {
37
            return <p className="modal-info__subtext">{item}</p>;
38
          },
39
        )}
40
        <div className="modal-info__list-wrapper">
41
          {Object.values(example_lists).map(
42
            (exampleList: any, i: number): React.ReactElement => {
43
              return (
44
                <>
45
                  <h4 className={i === 0 ? "color-green" : "color-red"}>
46
                    {exampleList.title}
47
                  </h4>
48
                  <ul>
49
                    {Object.values(exampleList.examples).map(
50
                      (example: any): React.ReactElement => {
51
                        return (
52
                          <li>
53
                            <p className="list-item__title">
54
                              {i === 0 ? (
55
                                <i className="far fa-check-circle" />
56
                              ) : (
57
                                <i className="far fa-times-circle" />
58
                              )}
59
                              {example.name}
60
                            </p>
61
                            {Array.isArray(example.content) ? (
62
                              Object.values(example.content).map(
63
                                (item: string): React.ReactElement => {
64
                                  return (
65
                                    <p className="list-item__content">{item}</p>
66
                                  );
67
                                },
68
                              )
69
                            ) : (
70
                              <p className="list-item__content">
71
                                {example.content}
72
                              </p>
73
                            )}
74
                          </li>
75
                        );
76
                      },
77
                    )}
78
                  </ul>
79
                </>
80
              );
81
            },
82
          )}
83
        </div>
84
      </div>
85
    </InfoModal>
86
  );
87
};
88
89
if (document.querySelectorAll("div[data-skills-info-modal]")) {
90
  const elements = document.querySelectorAll("div[data-skills-info-modal]");
91
92
  Array.prototype.slice.call(elements).forEach((container):
93
    | void
94
    | React.Component<any, any, any>
95
    | Element => {
96
    if (container != null && container.hasAttribute("data-skills-info-modal")) {
97
      const id = container.getAttribute("data-skills-info-modal") as string;
98
      const title = container.getAttribute("data-title") as string;
99
      const openText = container.getAttribute("data-open-text") as string;
100
      const confirmText = container.getAttribute("data-confirm-text") as string;
101
      const modalInfo = JSON.parse(container.getAttribute(
102
        "data-modal-info",
103
      ) as string);
104
105
      ReactDOM.render(
106
        <SkillsInfoModal
107
          key={id}
108
          id={id}
109
          title={title}
110
          openText={openText}
111
          confirmText={confirmText}
112
          modalInfo={modalInfo}
113
        />,
114
        container,
115
      );
116
    }
117
  });
118
}
119
120
export default SkillsInfoModal;
121