1
- import React from 'react' ;
1
+ import React , { useState } from 'react' ;
2
+ import { Typography } from '../../base' ;
2
3
import { ExternalLinkIcon } from '../../icons' ;
4
+ import { Modal , ModalBody , ModalButtonPrimary , ModalButtonSecondary , ModalFooter } from '../Modal' ;
3
5
import {
4
6
Card2 ,
5
7
CardActive ,
@@ -30,6 +32,8 @@ interface Props {
30
32
path ?: string ;
31
33
courseCount : number ;
32
34
courseType : string ;
35
+ orgId ?: string ;
36
+ modalContent ?: string ;
33
37
}
34
38
35
39
const OptionalLink : React . FC < React . PropsWithChildren < { path ?: string ; isExternal ?: boolean } > > = ( {
@@ -52,8 +56,19 @@ const OptionalLink: React.FC<React.PropsWithChildren<{ path?: string; isExternal
52
56
) ;
53
57
} ;
54
58
55
- const LearningCard : React . FC < Props > = ( { tutorial, path, courseCount, courseType } ) => {
59
+ const LearningCard : React . FC < Props > = ( {
60
+ tutorial,
61
+ path,
62
+ courseCount,
63
+ courseType,
64
+ orgId,
65
+ modalContent
66
+ } ) => {
56
67
const isCreateLearningPath = courseType === 'learning-card' ;
68
+ const [ modalOpen , setModalOpen ] = useState ( false ) ;
69
+
70
+ const handleModalOpen = ( ) => setModalOpen ( true ) ;
71
+ const handleModalClose = ( ) => setModalOpen ( false ) ;
57
72
return (
58
73
< CardWrapper >
59
74
{ tutorial . frontmatter . disabled === 'yes' ? (
@@ -80,9 +95,9 @@ const LearningCard: React.FC<Props> = ({ tutorial, path, courseCount, courseType
80
95
</ CardParent >
81
96
</ Card2 >
82
97
) : (
83
- < OptionalLink path = { path } isExternal = { isCreateLearningPath } >
98
+ < >
84
99
{ isCreateLearningPath ? (
85
- < OwnLearningCard >
100
+ < OwnLearningCard onClick = { handleModalOpen } style = { { cursor : 'pointer' } } >
86
101
< CardParent style = { { borderTop : `5px solid ${ tutorial . frontmatter . themeColor } ` } } >
87
102
< div >
88
103
< CardHead >
@@ -110,41 +125,72 @@ const LearningCard: React.FC<Props> = ({ tutorial, path, courseCount, courseType
110
125
</ CardParent >
111
126
</ OwnLearningCard >
112
127
) : (
113
- < CardActive >
114
- < CardParent style = { { borderTop : `5px solid ${ tutorial . frontmatter . themeColor } ` } } >
115
- < div >
116
- < CardHead >
117
- < h3 >
118
- { tutorial . frontmatter . title
119
- ? tutorial . frontmatter . title
120
- : tutorial . frontmatter . courseTitle }
121
- </ h3 >
122
- { tutorial . frontmatter . status ? (
123
- < p >
124
- < span > New</ span >
125
- </ p >
126
- ) : null }
127
- </ CardHead >
128
- < CardDesc >
129
- < p className = "summary" > { tutorial . frontmatter . description } </ p >
130
- </ CardDesc >
131
- { ! isCreateLearningPath && (
132
- < CardSubdata className = "card-subdata" >
133
- < p >
134
- { courseCount } { courseType }
135
- { courseCount > 1 ? 's' : '' }
136
- </ p >
137
- </ CardSubdata >
138
- ) }
139
- < CardImage >
140
- < img src = { tutorial . frontmatter . cardImage } />
141
- </ CardImage >
142
- </ div >
143
- </ CardParent >
144
- </ CardActive >
128
+ < OptionalLink path = { path } isExternal = { isCreateLearningPath } >
129
+ < CardActive >
130
+ < CardParent style = { { borderTop : `5px solid ${ tutorial . frontmatter . themeColor } ` } } >
131
+ < div >
132
+ < CardHead >
133
+ < h3 >
134
+ { tutorial . frontmatter . title
135
+ ? tutorial . frontmatter . title
136
+ : tutorial . frontmatter . courseTitle }
137
+ </ h3 >
138
+ { tutorial . frontmatter . status ? (
139
+ < p >
140
+ < span > New</ span >
141
+ </ p >
142
+ ) : null }
143
+ </ CardHead >
144
+ < CardDesc >
145
+ < p className = "summary" > { tutorial . frontmatter . description } </ p >
146
+ </ CardDesc >
147
+ { ! isCreateLearningPath && (
148
+ < CardSubdata className = "card-subdata" >
149
+ < p >
150
+ { courseCount } { courseType }
151
+ { courseCount > 1 ? 's' : '' }
152
+ </ p >
153
+ </ CardSubdata >
154
+ ) }
155
+ < CardImage >
156
+ < img src = { tutorial . frontmatter . cardImage } />
157
+ </ CardImage >
158
+ </ div >
159
+ </ CardParent >
160
+ </ CardActive >
161
+ </ OptionalLink >
145
162
) }
146
- </ OptionalLink >
163
+ </ >
147
164
) }
165
+
166
+ < Modal
167
+ open = { modalOpen }
168
+ closeModal = { handleModalClose }
169
+ title = { tutorial . frontmatter . title || tutorial . frontmatter . courseTitle }
170
+ maxWidth = "sm"
171
+ >
172
+ < ModalBody >
173
+ < Typography variant = "body1" > { modalContent } </ Typography >
174
+ { orgId && (
175
+ < Typography variant = "body1" color = "textSecondary" >
176
+ Your Organization ID: { orgId }
177
+ </ Typography >
178
+ ) }
179
+ </ ModalBody >
180
+ < ModalFooter variant = "filled" >
181
+ < ModalButtonSecondary onClick = { handleModalClose } > Close</ ModalButtonSecondary >
182
+ { path && (
183
+ < ModalButtonPrimary
184
+ onClick = { ( ) => {
185
+ window . open ( path , '_blank' ) ;
186
+ handleModalClose ( ) ;
187
+ } }
188
+ >
189
+ Visit Docs
190
+ </ ModalButtonPrimary >
191
+ ) }
192
+ </ ModalFooter >
193
+ </ Modal >
148
194
</ CardWrapper >
149
195
) ;
150
196
} ;
0 commit comments