-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed: Fix play again URL rendering (#1051)
* fix: return play again url as a relative url instead of an absolute url * fix: Render a Link or an anchor tag (<a>), depending on whether the url received from the Final action is relative or absolute * fix: Render non-linkoneous button when button.link is nullish or an empty string * fix: Fix conditional rendering logic & open absolute url in new tab * story: Update stories for specific button/link types for Final component * fix: Refactor Final component to use FinalButton for rendering buttons * docs: Add comments to FinalButton component
- Loading branch information
1 parent
d5e7fb8
commit f6183fd
Showing
11 changed files
with
193 additions
and
36 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from "react"; | ||
import { Link, withRouter } from "react-router-dom"; | ||
|
||
interface FinalButtonProps { | ||
button: { | ||
text: string; | ||
link: string; | ||
}; | ||
onNext: (value: boolean) => void; | ||
} | ||
|
||
const isRelativeUrl = (url: string) => { | ||
return url && url.startsWith("/"); | ||
} | ||
|
||
const FinalButton: React.FC<FinalButtonProps> = ({ button, onNext }) => { | ||
|
||
if (!button) { | ||
return null; | ||
} | ||
|
||
// If the button does not have a link, it will call the onNext function using a button click event | ||
if (!button.link) { | ||
return ( | ||
<button data-testid="button" className='btn btn-primary btn-lg' onClick={() => onNext(false)}> | ||
{button.text} | ||
</button> | ||
) | ||
} | ||
|
||
// If the button has a link, it will render a Link component if the link is a relative URL | ||
if (isRelativeUrl(button.link)) { | ||
return ( | ||
<Link data-testid="button-link" className='btn btn-primary btn-lg' to={button.link}> | ||
{button.text} | ||
</Link> | ||
) | ||
} | ||
|
||
// If the button has a link, it will render an anchor tag if the link is an absolute URL | ||
return ( | ||
<a data-testid="button-link" className='btn btn-primary btn-lg' href={button.link} target="_blank" rel="noopener noreferrer"> | ||
{button.text} | ||
</a> | ||
) | ||
} | ||
|
||
export default withRouter(FinalButton); |
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