Skip to content

Commit

Permalink
done with messages
Browse files Browse the repository at this point in the history
  • Loading branch information
truell20 committed Mar 30, 2023
1 parent 70d706b commit b85efe2
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 40 deletions.
127 changes: 92 additions & 35 deletions src/components/errors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,31 @@ import {getShowErrors, getError} from '../features/selectors';
import { faClose } from '@fortawesome/pro-regular-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import Modal from 'react-modal'
import { NoAuthRateLimitError, NotLoggedInError, OpenAIError } from '../utils';
import { NoAuthGlobalOldRateLimitError, NotLoggedInError, OpenAIError } from '../utils';
import { CursorLogin, OpenAILoginPanel } from './settingsPane';

const customStyles = {
overlay: {
backgroundColor: 'rgba(0, 0, 0, 0.1)',
display: 'flex',
alignItems: 'center',
zIndex: 10000,
},
content: {
padding: 'none',
top: '150px',
bottom: 'none',
background: 'none',
border: 'none',
width: 'auto',
height: 'auto',
marginLeft: 'auto',
marginRight: 'auto',
maxWidth: '600px',
},
}

const loginStyles = {
overlay: {
backgroundColor: 'rgba(0, 0, 0, 0.1)',
display: 'flex',
Expand All @@ -32,12 +53,10 @@ const customStyles = {

export function ErrorPopup() {
const showError = useAppSelector(getShowErrors)
const error = new NotLoggedInError()
const error = useAppSelector(getError)
const dispatch = useAppDispatch()

console.log('waht')

if (false && error == null) {
if (error == null) {
return (
<Modal
isOpen={showError}
Expand Down Expand Up @@ -66,14 +85,14 @@ export function ErrorPopup() {
</div>
</Modal>
)
} else if (true || error instanceof NotLoggedInError) {
} else if (error instanceof NotLoggedInError) {
return (
<Modal
isOpen={true || showError}
isOpen={showError}
onRequestClose={() => {
dispatch(closeError())
}}
style={customStyles}
style={loginStyles}
>
<div className="errorPopup">
<div className="errorPopup__title">
Expand Down Expand Up @@ -105,34 +124,72 @@ export function ErrorPopup() {
</div>
</Modal>
)
} else if (error instanceof NoAuthGlobalOldRateLimitError) {
return (
<Modal
isOpen={true || showError}
onRequestClose={() => {
dispatch(closeError())
}}
style={loginStyles}
>
<div className="errorPopup">
<div className="errorPopup__title">
<div className="errorPopup__title_text">
</div>
<div
className="errorPopup__title_close"
onClick={() => dispatch(closeError())}
>
<FontAwesomeIcon icon={faClose} />
</div>
</div>
<div className="signup__body">
<div className="signup__title">Free tier limit exceeded</div>
<div className="signup__module">
<div className="signup__subtitle">If you've enjoyed using Cursor, please consider subscribing to one of our paid plans</div>
<div className="signup__signup_button">Upgrade</div>
</div>
<div className="signup__module signup__last_module">
<div className="signup__subtitle">Or enter your OpenAI API key to continue using the AI features at-cost</div>
<OpenAILoginPanel onSubmit={
() => {
dispatch(closeError())
}
} />
</div>
</div>
</div>
</Modal>
)
} else {
// return (
// <Modal
// isOpen={showError}
// onRequestClose={() => {
// dispatch(closeError())
// }}
// style={customStyles}
// >
// <div className="errorPopup">
// <div className="errorPopup__title">
// <div className="errorPopup__title_text">
// {error.title}
// </div>
// <div
// className="errorPopup__title_close"
// onClick={() => dispatch(closeError())}
// >
// <FontAwesomeIcon icon={faClose} />
// </div>
// </div>
// <div className="errorPopup__body">
// {error.message}
// <br />
// </div>
// </div>
// </Modal>
// )
return (
<Modal
isOpen={true || showError}
onRequestClose={() => {
dispatch(closeError())
}}
style={customStyles}
>
<div className="errorPopup">
<div className="errorPopup__title">
<div className="errorPopup__title_text">
{/* {error.title} */}
</div>
<div
className="errorPopup__title_close"
onClick={() => dispatch(closeError())}
>
<FontAwesomeIcon icon={faClose} />
</div>
</div>
<div className="errorPopup__body">
{/* {error.message} */}
<br />
</div>
</div>
</Modal>
)
}


Expand Down
15 changes: 10 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,50 @@ export class ExpectedBackendError extends Error {

export class NoAuthRateLimitError extends ExpectedBackendError {
constructor(
message = 'You have reached the rate limit for unauthenticated requests. Please authenticate to continue.'
message = 'You\'ve reached the rate limit for unauthenticated requests. Please log in to continue.',
) {
super(message)
this.name = 'NoAuthRateLimitError'
this.title = 'Please log in to continue...'
}
}

export class AuthRateLimitError extends ExpectedBackendError {
constructor(
message = 'You have reached the rate limit for authenticated requests. Please wait before making more requests.'
message = 'It seems like you\'re making an unusual number of AI requests. Please try again later. If you think this is a mistake, please contact [email protected]'
) {
super(message)
this.name = 'AuthRateLimitError'
this.title = 'You\'re going a bit fast...'
} }

export class NoAuthLocalRateLimitError extends ExpectedBackendError {
constructor(
message = 'You have reached the rate limit for unauthenticated local requests. Please authenticate to continue.'
message = 'To protect our backend, we ask that free users limit their usage to 30 prompts per hour. To raise this limit, feel free to upgrade to pro.'
) {
super(message)
this.name = 'NoAuthLocalRateLimitError'
this.title = 'You\'re going a bit fast...'
}
}

export class NoAuthGlobalOldRateLimitError extends ExpectedBackendError {
constructor(
message = 'You have reached the rate limit for unauthenticated global requests. Please wait before making more requests.'
message = 'If you\'ve enjoyed using Cursor, please consider subscribing to one of our paid plans. Otherwise, you can enter your Open AI key (gear icon) to continue using the AI features at-cost.'
) {
super(message)
this.name = 'NoAuthGlobalOldRateLimitError'
this.title = 'Free tier limit exceeded'
}
}

export class NoAuthGlobalNewRateLimitError extends ExpectedBackendError {
constructor(
message = 'You have reached the rate limit for unauthenticated global requests. Please wait before making more requests.'
message = 'We\'re currently experiencing a high volume of requests. Please try again in a few minutes. For support, please contact [email protected].'
) {
super(message)
this.name = 'NoAuthGlobalNewRateLimitError'
this.title = 'Our servers are overloaded...'
}
}

Expand Down

0 comments on commit b85efe2

Please sign in to comment.