Skip to content

Commit

Permalink
fix: remove protocol before showing on popup screen
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijithvijayan committed Mar 16, 2020
1 parent 1077348 commit a2b9bc1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 30 deletions.
34 changes: 19 additions & 15 deletions src/Popup/PopupBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import CopyToClipboard from 'react-copy-to-clipboard';
import QRCode from 'qrcode.react';

import Icon from '../components/Icon';
import { removeProtocol } from '../util/link';

export type ProcessedRequestProperties = {
error: boolean | null;
Expand All @@ -27,8 +28,8 @@ const PopupBody: React.FC<PopupBodyProperties> = ({ requestProcessed: { message,
return (
<>
<div className="popup__body">
{!error && (
<div>
{!error ? (
<>
<button
className="icon__button"
type="button"
Expand All @@ -38,27 +39,30 @@ const PopupBody: React.FC<PopupBodyProperties> = ({ requestProcessed: { message,
>
<Icon className="qr__icon" name="qrcode" />
</button>

{!copied ? (
<CopyToClipboard
text={message}
onCopy={(): void => {
return setCopied(true);
}}
>
<Icon className="copy__icon" name="copy" />
</CopyToClipboard>
) : (
<Icon name="tick" />
)}
<CopyToClipboard
text={message}
onCopy={(): void => {
return setCopied(true);
}}
>
{!copied ? (
<button className="icon__button" type="button">
<Icon className="copy__icon" name="copy" />
</button>
) : (
<button type="button">
<Icon name="tick" />
</button>
)}
<p>{removeProtocol(message)}</p>
</CopyToClipboard>
</div>
</>
) : (
<p>{message}</p>
)}

<p>{message}</p>
</div>

{!error && QRView && (
Expand Down
5 changes: 3 additions & 2 deletions src/Popup/PopupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const PopupForm = withFormik<PopupFormProperties, PopupFormValuesProperties>({
// ToDo: Remove special symbols from password & customurl fields

// password validation
if (values.password && values.password.trim().length < 1) {
if (values.password && values.password.trim().length < 3) {
errors.password = 'Password must be atleast 3 characters';
}
// custom url validation
Expand Down Expand Up @@ -153,9 +153,10 @@ const PopupForm = withFormik<PopupFormProperties, PopupFormValuesProperties>({
const {
data: { link },
} = response;
const trimmedLink: string = link.replace('https://', '');

// show shortened url
setRequestProcessed({ error: false, message: link });
setRequestProcessed({ error: false, message: trimmedLink });
} else {
// errored
setRequestProcessed({ error: true, message: response.message });
Expand Down
28 changes: 15 additions & 13 deletions src/Popup/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ body {

.popup__form {
padding: 15px 15px;

h4 {
padding: 10px 0px 5px 0px;
font-size: 0.9em;
Expand Down Expand Up @@ -41,24 +42,24 @@ body {
display: flex;
justify-content: center;
padding: 15px 15px 0px 15px;

p {
padding-top: 5px;
text-decoration: underline;
font-size: 1.2em;
}
.icon__button {

.copy__icon {
display: block;
padding-right: 5px;
cursor: pointer;
}

.qr__icon {
display: block;
padding-right: 5px;
padding-top: 5px;
cursor: pointer;
.copy__icon {
display: block;
padding-right: 5px;
cursor: pointer;
}
.qr__icon {
display: block;
padding-right: 5px;
padding-top: 5px;
cursor: pointer;
}
}
}

Expand Down Expand Up @@ -92,9 +93,10 @@ body {
background-color: transparent !important;
cursor: pointer;
}

.refresh__icon {
cursor: pointer;
padding-right: 5px;
}
}
}
}
3 changes: 3 additions & 0 deletions src/util/link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const removeProtocol = (link: string): string => {
return link.replace(/^https?:\/\//, '');
};

0 comments on commit a2b9bc1

Please sign in to comment.