11import { FC , useEffect , useMemo , useCallback } from 'react' ;
22import "../sass/result_page.scss"
3+ import { Link } from 'react-router-dom' ;
4+ import { Links } from "@enums/Links.enum"
35
46import { useMutation } from '@tanstack/react-query' ;
57import { useSelector } from 'react-redux' ;
@@ -10,6 +12,8 @@ import { addVariousInfoToServer } from '@slices-my/various_info.slice';
1012import { VariousInfoToServer } from '@types-my/Form.type' ;
1113import { FullInfo } from '@types-my/Fetch.type' ;
1214
15+ import wordImg from "/img/word.png"
16+
1317const ResultPage : FC = ( ) => {
1418 const various_data = useSelector ( ( state : RootState ) => state . various_info . various_info_to_server ) ;
1519 const dispatch = useAppDispatch ( ) ;
@@ -33,9 +37,10 @@ const ResultPage: FC = () => {
3337 share_size_with_common_denominator,
3438 } ;
3539
36- for ( let j = 0 ; j < general_info . number_questions ; j ++ ) {
37- newData . push ( { ...obj , number_day : j } ) ;
38- }
40+ for ( let j = 0 ; j <= general_info . number_questions ; j ++ ) {
41+ const number_day = j == general_info . number_questions ? '____' : j + 1 ;
42+ newData . push ( { ...obj , number_day } ) ;
43+ }
3944 }
4045 dispatch ( addVariousInfoToServer ( newData ) ) ;
4146 } , [ various_info , general_info , dispatch ] ) ;
@@ -63,17 +68,14 @@ const ResultPage: FC = () => {
6368 const contentType = res . headers . get ( "Content-Type" ) ;
6469
6570 if ( contentType && contentType . includes ( "application/json" ) ) {
66- req = res . json ( ) ;
71+ req = await res . json ( ) ;
6772 if ( ! res . ok ) throw new Error ( req . message )
6873 } else if ( contentType && contentType . includes ( "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ) ) {
69- req = res . blob ( ) ;
74+ req = await res . blob ( ) ;
7075 return req
7176 } else {
7277 throw new Error ( "Unexpected content type" ) ;
7378 }
74-
75-
76-
7779 }
7880 } ) ;
7981
@@ -93,25 +95,51 @@ const ResultPage: FC = () => {
9395
9496 if ( ! blob ) throw new Error ( 'Ошибка' )
9597
96- const url = window . URL . createObjectURL ( blob ) ; // Use window.URL
98+ const url = window . URL . createObjectURL ( blob ) ;
9799 const link = document . createElement ( 'a' ) ;
98100 link . href = url ;
99- link . setAttribute ( 'download' , 'document .docx' ) ; // Use setAttribute
101+ link . setAttribute ( 'download' , 'bullet .docx' ) ;
100102 document . body . appendChild ( link ) ;
101- link . style . display = 'none' ; // Hide the link
103+ link . style . display = 'none' ;
102104 link . click ( ) ;
103- window . URL . revokeObjectURL ( url ) ; // Use window.URL
105+ window . URL . revokeObjectURL ( url ) ;
104106 document . body . removeChild ( link ) ;
105107 } catch ( error : any ) {
106108 console . error ( 'Error downloading document:' , error . message ) ;
107109 }
108110 } , [ mutation , req_body ] ) ;
109111
112+ const handleBack = ( ) => {
113+ document . location . pathname = '/' ;
114+
115+ localStorage . removeItem ( 'day' ) ;
116+ localStorage . removeItem ( 'mouth' ) ;
117+ localStorage . removeItem ( 'year' ) ;
118+ localStorage . removeItem ( 'c_1' ) ;
119+ localStorage . removeItem ( 'c_2' ) ;
120+ localStorage . removeItem ( 'c_3' ) ;
121+ localStorage . removeItem ( 'c_y' ) ;
122+ localStorage . removeItem ( 'area' ) ;
123+ localStorage . removeItem ( 'address' ) ;
124+ localStorage . removeItem ( 'number_quest' ) ;
125+ }
126+
110127 return (
111128 < >
112129 < h1 > Финальный этап</ h1 >
113- < p > { mutation . error && mutation . error . message } </ p >
114- < button disabled = { mutation . isError } onClick = { handleDownload } > Скачать</ button >
130+ < div id = "finally" >
131+ < div id = "info_file" >
132+ < img width = { 48 } src = { wordImg } alt = "Word Document" />
133+ < span > bullet.docx</ span >
134+ </ div >
135+
136+ < button id = 'download' disabled = { mutation . isError || mutation . isPending } onClick = { handleDownload } > { mutation . isPending ? 'Генерация...' : 'Скачать' } </ button >
137+ < p className = 'validate_error' > { mutation . error && mutation . error . message } </ p >
138+ </ div >
139+ { ! mutation . isError && < span > Ваши бюллетени успешно сгенерировались. В случае каких-либо неисправностей прошу Вас написать нам
140+ сюда: < code > ivan.minevskiy@yandex.ru</ code > .
141+ </ span > }
142+ < div className = 'center' > < Link onClick = { handleBack } to = { Links . MAIN_PAGE } > Вернуться назад</ Link > </ div >
115143 </ >
116144 ) ;
117145} ;
0 commit comments