-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathErrorModal.jsx
More file actions
107 lines (96 loc) · 2.52 KB
/
ErrorModal.jsx
File metadata and controls
107 lines (96 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import PropTypes from 'prop-types';
import React from 'react';
import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import prettyBytes from 'pretty-bytes';
import { getConfig } from '../../../utils/getConfig';
import { parseNumber } from '../../../utils/parseStringToType';
const uploadLimit = parseNumber(getConfig('UPLOAD_LIMIT')) || 250000000;
const uploadLimitText = prettyBytes(uploadLimit);
const ErrorModal = ({ type, service, closeModal }) => {
const { t } = useTranslation();
function forceAuthentication() {
return (
<p>
{t('ErrorModal.MessageLogin')}
<Link to="/login" onClick={closeModal}>
{' '}
{t('ErrorModal.Login')}
</Link>
{t('ErrorModal.LoginOr')}
<Link to="/signup" onClick={closeModal}>
{t('ErrorModal.SignUp')}
</Link>
.
</p>
);
}
function oauthError() {
const serviceLabels = {
github: 'GitHub',
google: 'Google'
};
return (
<p>
{t('ErrorModal.LinkMessage', { serviceauth: serviceLabels[service] })}
</p>
);
}
function staleSession() {
return (
<p>
{t('ErrorModal.MessageLoggedOut')}
<Link to="/login" onClick={closeModal}>
{t('ErrorModal.LogIn')}
</Link>
.
</p>
);
}
function staleProject() {
return <p>{t('ErrorModal.SavedDifferentWindow')}</p>;
}
function uploadLimitReached() {
return (
<p>
{t('UploadFileModal.SizeLimitError', { sizeLimit: uploadLimitText })}
<Link to="/assets" onClick={closeModal}>
assets
</Link>
.
</p>
);
}
return (
<div className="error-modal__content">
{(() => { // eslint-disable-line
if (type === 'forceAuthentication') {
return forceAuthentication();
} else if (type === 'staleSession') {
return staleSession();
} else if (type === 'staleProject') {
return staleProject();
} else if (type === 'uploadLimit') {
return uploadLimitReached();
} else if (type === 'oauthError') {
return oauthError();
}
})()}
</div>
);
};
ErrorModal.propTypes = {
type: PropTypes.oneOf([
'forceAuthentication',
'staleSession',
'staleProject',
'oauthError',
'uploadLimit'
]).isRequired,
closeModal: PropTypes.func.isRequired,
service: PropTypes.oneOf(['google', 'github'])
};
ErrorModal.defaultProps = {
service: ''
};
export default ErrorModal;