-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from ameerul-deriv/add-endpoint-page
Feature: Add Endpoint page
- Loading branch information
Showing
8 changed files
with
114 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './screens'; |
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,15 @@ | ||
.endpoint { | ||
position: absolute; | ||
top: 8rem; | ||
background: #fff; | ||
width: 100%; | ||
height: 60%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
|
||
@include mobile { | ||
height: unset; | ||
padding-top: 2rem; | ||
} | ||
} |
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,81 @@ | ||
import { Controller, useForm } from 'react-hook-form'; | ||
import { Button, Input, Text } from '@deriv-com/ui'; | ||
import { LocalStorageConstants, LocalStorageUtils } from '@deriv-com/utils'; | ||
import './Endpoint.scss'; | ||
|
||
const Endpoint = () => { | ||
const { | ||
control, | ||
formState: { isDirty, isValid }, | ||
getValues, | ||
handleSubmit, | ||
reset, | ||
} = useForm({ | ||
defaultValues: { | ||
serverUrl: localStorage.getItem(LocalStorageConstants.configServerURL.toString()) || '', | ||
appId: LocalStorageUtils.getValue(LocalStorageConstants.configAppId) || '', | ||
}, | ||
mode: 'onChange', | ||
}); | ||
|
||
return ( | ||
<div className='endpoint flex flex-col gap-8'> | ||
<Text weight='bold'>Change API endpoint</Text> | ||
<form className='flex flex-col' action=''> | ||
<Controller | ||
control={control} | ||
name='serverUrl' | ||
render={({ field: { onBlur, onChange, value }, fieldState: { error } }) => ( | ||
<Input | ||
label='Server' | ||
message={error?.message} | ||
onBlur={onBlur} | ||
onChange={onChange} | ||
value={value} | ||
/> | ||
)} | ||
rules={{ | ||
required: 'This field is required', | ||
}} | ||
/> | ||
<Controller | ||
control={control} | ||
name='appId' | ||
render={({ field: { onBlur, onChange, value }, fieldState: { error } }) => ( | ||
<Input | ||
label='OAuth App ID' | ||
message={error?.message} | ||
onBlur={onBlur} | ||
onChange={onChange} | ||
value={value} | ||
/> | ||
)} | ||
rules={{ | ||
required: 'This field is required', | ||
pattern: { | ||
message: 'Please enter a valid app ID', | ||
value: /^(0|[1-9]\d*)(\.\d+)?$/, | ||
}, | ||
}} | ||
/> | ||
<Button | ||
className='w-40' | ||
disabled={!isDirty || !isValid} | ||
onClick={handleSubmit(() => { | ||
// Can't use LocalStorageUtils.setValue because it will place "" around the value | ||
localStorage.setItem(LocalStorageConstants.configServerURL, getValues('serverUrl')); | ||
localStorage.setItem(LocalStorageConstants.configAppId, getValues('appId')); | ||
reset({ | ||
serverUrl: getValues('serverUrl'), | ||
appId: getValues('appId'), | ||
}); | ||
})} | ||
> | ||
Submit | ||
</Button> | ||
</form> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Endpoint; |
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 @@ | ||
export { default as Endpoint } from './Endpoint'; |
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 @@ | ||
export * from './Endpoint'; |
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