-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(files): prefer subdomain gw in copied share links (#2255)
Co-authored-by: Marcin Rataj <[email protected]> Co-authored-by: Russell Dempsey <[email protected]>
- Loading branch information
1 parent
eefae25
commit e8c4421
Showing
10 changed files
with
362 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/components/public-subdomain-gateway-form/PublicSubdomainGatewayForm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import React, { useState, useEffect } from 'react' | ||
import { connect } from 'redux-bundler-react' | ||
import { withTranslation } from 'react-i18next' | ||
import Button from '../button/Button.js' | ||
import { checkValidHttpUrl, checkSubdomainGateway, DEFAULT_SUBDOMAIN_GATEWAY } from '../../bundles/gateway.js' | ||
|
||
const PublicSubdomainGatewayForm = ({ t, doUpdatePublicSubdomainGateway, publicSubdomainGateway }) => { | ||
const [value, setValue] = useState(publicSubdomainGateway) | ||
const initialIsValidGatewayUrl = !checkValidHttpUrl(value) | ||
const [isValidGatewayUrl, setIsValidGatewayUrl] = useState(initialIsValidGatewayUrl) | ||
|
||
// Updates the border of the input to indicate validity | ||
useEffect(() => { | ||
const validateUrl = async () => { | ||
try { | ||
const isValid = await checkSubdomainGateway(value) | ||
setIsValidGatewayUrl(isValid) | ||
} catch (error) { | ||
console.error('Error checking subdomain gateway:', error) | ||
setIsValidGatewayUrl(false) | ||
} | ||
} | ||
|
||
validateUrl() | ||
}, [value]) | ||
|
||
const onChange = (event) => setValue(event.target.value) | ||
|
||
const onSubmit = async (event) => { | ||
event.preventDefault() | ||
|
||
let isValid = false | ||
try { | ||
isValid = await checkSubdomainGateway(value) | ||
setIsValidGatewayUrl(true) | ||
} catch (e) { | ||
setIsValidGatewayUrl(false) | ||
return | ||
} | ||
|
||
isValid && doUpdatePublicSubdomainGateway(value) | ||
} | ||
|
||
const onReset = async (event) => { | ||
event.preventDefault() | ||
setValue(DEFAULT_SUBDOMAIN_GATEWAY) | ||
doUpdatePublicSubdomainGateway(DEFAULT_SUBDOMAIN_GATEWAY) | ||
} | ||
|
||
const onKeyPress = (event) => { | ||
if (event.key === 'Enter') { | ||
onSubmit(event) | ||
} | ||
} | ||
|
||
return ( | ||
<form onSubmit={onSubmit}> | ||
<input | ||
id='public-subdomain-gateway' | ||
aria-label={t('terms.publicSubdomainGateway')} | ||
placeholder={t('publicSubdomainGatewayForm.placeholder')} | ||
type='text' | ||
className={`w-100 lh-copy monospace f5 pl1 pv1 mb2 charcoal input-reset ba b--black-20 br1 ${!isValidGatewayUrl ? 'focus-outline-red b--red-muted' : 'focus-outline-green b--green-muted'}`} | ||
onChange={onChange} | ||
onKeyPress={onKeyPress} | ||
value={value} | ||
/> | ||
<div className='tr'> | ||
<Button | ||
id='public-subdomain-gateway-reset-button' | ||
minWidth={100} | ||
height={40} | ||
bg='bg-charcoal' | ||
className='tc' | ||
disabled={value === DEFAULT_SUBDOMAIN_GATEWAY} | ||
onClick={onReset}> | ||
{t('app:actions.reset')} | ||
</Button> | ||
<Button | ||
id='public-subdomain-gateway-submit-button' | ||
minWidth={100} | ||
height={40} | ||
className='mt2 mt0-l ml2-l tc' | ||
disabled={!isValidGatewayUrl || value === publicSubdomainGateway}> | ||
{t('actions.submit')} | ||
</Button> | ||
</div> | ||
</form> | ||
) | ||
} | ||
|
||
export default connect( | ||
'doUpdatePublicSubdomainGateway', | ||
'selectPublicSubdomainGateway', | ||
withTranslation('app')(PublicSubdomainGatewayForm) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.