@@ -23,6 +23,7 @@ import {
23
23
useLocation ,
24
24
useNavigate ,
25
25
useRef ,
26
+ useState ,
26
27
} from '~/bundles/common/hooks/hooks.js' ;
27
28
import { IconName } from '~/bundles/common/icons/icons.js' ;
28
29
import { notificationService } from '~/bundles/common/services/services.js' ;
@@ -33,6 +34,7 @@ import {
33
34
Timeline ,
34
35
VideoMenu ,
35
36
VideoNameInput ,
37
+ WarningModal ,
36
38
} from '../components/components.js' ;
37
39
import {
38
40
SCRIPT_AND_AVATAR_ARE_REQUIRED ,
@@ -42,12 +44,13 @@ import {
42
44
VIDEO_SUBMIT_NOTIFICATION_ID ,
43
45
} from '../constants/constants.js' ;
44
46
import { NotificationMessage , NotificationTitle } from '../enums/enums.js' ;
45
- import { getVoicesConfigs } from '../helpers/helpers.js' ;
47
+ import { getVoicesConfigs , scenesExceedScripts } from '../helpers/helpers.js' ;
46
48
import { selectVideoDataById } from '../store/selectors.js' ;
47
49
import { actions as studioActions } from '../store/studio.js' ;
48
50
49
51
const Studio : React . FC = ( ) => {
50
52
const { state : locationState } = useLocation ( ) ;
53
+ const [ isModalOpen , setIsModalOpen ] = useState ( false ) ;
51
54
52
55
const videoData = useAppSelector ( ( state ) =>
53
56
selectVideoDataById ( state , locationState ?. id ) ,
@@ -60,6 +63,14 @@ const Studio: React.FC = () => {
60
63
const dispatch = useAppDispatch ( ) ;
61
64
const navigate = useNavigate ( ) ;
62
65
66
+ const handleOpenModal = useCallback ( ( ) => {
67
+ setIsModalOpen ( true ) ;
68
+ } , [ ] ) ;
69
+
70
+ const handleCloseModal = useCallback ( ( ) => {
71
+ setIsModalOpen ( false ) ;
72
+ } , [ ] ) ;
73
+
63
74
useEffect ( ( ) : void => {
64
75
if ( videoData ) {
65
76
void dispatch ( studioActions . loadVideoData ( videoData ) ) ;
@@ -70,11 +81,10 @@ const Studio: React.FC = () => {
70
81
dispatch ( studioActions . changeVideoSize ( ) ) ;
71
82
} , [ dispatch ] ) ;
72
83
73
- const handleSubmit = useCallback ( ( ) => {
84
+ const handleConfirmSubmit = useCallback ( ( ) => {
74
85
// TODO: REPLACE LOGIC WITH MULTIPLE SCENES
75
86
const scene = scenes [ 0 ] ;
76
87
const script = scripts [ 0 ] ;
77
-
78
88
if ( ! scene ?. avatar || ! script ) {
79
89
notificationService . warn ( {
80
90
id : SCRIPT_AND_AVATAR_ARE_REQUIRED ,
@@ -106,6 +116,14 @@ const Studio: React.FC = () => {
106
116
} ) ;
107
117
} , [ dispatch , navigate , scenes , scripts ] ) ;
108
118
119
+ const handleSubmit = useCallback ( ( ) => {
120
+ if ( scenesExceedScripts ( scenes , scripts ) ) {
121
+ handleOpenModal ( ) ;
122
+ } else {
123
+ handleConfirmSubmit ( ) ;
124
+ }
125
+ } , [ handleConfirmSubmit , handleOpenModal , scenes , scripts ] ) ;
126
+
109
127
useEffect ( ( ) => {
110
128
return ( ) => {
111
129
dispatch ( studioActions . resetStudio ( ) ) ;
@@ -171,6 +189,11 @@ const Studio: React.FC = () => {
171
189
display = "flex"
172
190
flexDirection = "column"
173
191
>
192
+ < WarningModal
193
+ isOpen = { isModalOpen }
194
+ onClose = { handleCloseModal }
195
+ onSubmit = { handleConfirmSubmit }
196
+ />
174
197
< Header
175
198
center = {
176
199
< Button
0 commit comments