Skip to content

Commit eb5bf3b

Browse files
debug
1 parent 677c081 commit eb5bf3b

File tree

11 files changed

+131
-263
lines changed

11 files changed

+131
-263
lines changed

client/public/img/word.png

24.7 KB
Loading

client/src/components/form_parts/Area.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ const ls = localStorage.getItem('area') || ''
3232
min: {
3333
value: 1,
3434
message: "Некорректная площадь"
35+
},
36+
max: {
37+
value: 9999999999,
38+
message: "Некорректная площадь"
3539
}
3640
})}
3741
/>

client/src/pages/Result.page.tsx

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { FC, useEffect, useMemo, useCallback } from 'react';
22
import "../sass/result_page.scss"
3+
import { Link } from 'react-router-dom';
4+
import { Links } from "@enums/Links.enum"
35

46
import { useMutation } from '@tanstack/react-query';
57
import { useSelector } from 'react-redux';
@@ -10,6 +12,8 @@ import { addVariousInfoToServer } from '@slices-my/various_info.slice';
1012
import { VariousInfoToServer } from '@types-my/Form.type';
1113
import { FullInfo } from '@types-my/Fetch.type';
1214

15+
import wordImg from "/img/word.png"
16+
1317
const 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
};

client/src/sass/result_page.scss

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
@font-face {
2+
font-family: Montserrat-Italic;
3+
src: url("/fonts/Montserrat-Italic.ttf");
4+
}
5+
.validate_error {
6+
margin-left: 30px;
7+
color: red;
8+
font-size: 30px;
9+
font-family: Verdana, sans-serif;
10+
}
11+
#info_file {
12+
display: flex;
13+
flex-direction: row;
14+
margin-left: 30px;
15+
gap: 15px;
16+
margin-bottom: 20px;
17+
}
18+
19+
#finally {
20+
display: flex;
21+
flex-direction: column;
22+
justify-content: center;
23+
align-items: center;
24+
}
25+
#download {
26+
height: 50px;
27+
}
28+
a {
29+
transition: 300ms;
30+
text-decoration: none;
31+
color: blue;
32+
font-size: 30px;
33+
font-family: "Montserrat-Italic", sans-serif;
34+
&:hover {
35+
color: rgb(42, 42, 177);
36+
}
37+
}
38+
.center {
39+
display: flex;
40+
justify-content: center;
41+
}

0 commit comments

Comments
 (0)