Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VACMS-18457 Implement action links on Event CTAs #850

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions additional.d.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
/// <reference types="react-scripts" />

declare module 'nock'
declare module 'test-utils'
declare module '@testing-library/react'
declare module '@department-of-veterans-affairs/component-library'
declare module '@department-of-veterans-affairs/component-library/Table'
declare module '@department-of-veterans-affairs/component-library/LoadingIndicator'
declare module '@department-of-veterans-affairs/component-library/AlertBox'
declare module '@department-of-veterans-affairs/component-library/DropDownPanel'
declare module '@department-of-veterans-affairs/component-library/Breadcrumbs'
declare module '@department-of-veterans-affairs/component-library/Banner'
declare module '@department-of-veterans-affairs/component-library/TextInput'
declare module '@department-of-veterans-affairs/component-library/TextArea'
declare module '@department-of-veterans-affairs/component-library/Breadcrumbs'
declare module '@department-of-veterans-affairs/component-library/dist/react-bindings'
declare module '@department-of-veterans-affairs/component-library/DropDownPanel'
declare module '@department-of-veterans-affairs/component-library/LoadingIndicator'
declare module '@department-of-veterans-affairs/component-library/Modal'
declare module '@department-of-veterans-affairs/component-library/Pagination'
declare module '@department-of-veterans-affairs/component-library/ProgressButton'
declare module '@department-of-veterans-affairs/component-library/PromoBanner'
declare module '@department-of-veterans-affairs/component-library/dist/react-bindings'
declare module 'mq-polyfill'
declare module '@department-of-veterans-affairs/component-library/Table'
declare module '@department-of-veterans-affairs/component-library/TextArea'
declare module '@department-of-veterans-affairs/component-library/TextInput'
declare module '@testing-library/react'
declare module 'debug'
declare module 'mq-polyfill'
declare module 'nock'
declare module 'test-utils'

declare namespace JSX {
interface IntrinsicElements {
'va-accordion-item'
'va-accordion'
'va-alert'
'va-link'
'va-icon'
'va-button'
'va-back-to-top'
'va-breadcrumbs'
'va-accordion'
'va-accordion-item'
'va-button'
'va-icon'
'va-link'
'va-link-action'
'va-on-this-page'
'va-back-to-top'
}
}
7 changes: 7 additions & 0 deletions src/lib/utils/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { formatEventCTA, createMailToLink } from './events'

describe('formatEventCTA', () => {
describe('formatEventCTA', () => {
it('should format "rsvp" as "RSVP"', () => {
const input = 'rsvp'
const expected = 'RSVP'
const result = formatEventCTA(input)
expect(result).toBe(expected)
})

it('should format "register_now" as "Register now"', () => {
const input = 'register_now'
const expected = 'Register now'
Expand Down
4 changes: 4 additions & 0 deletions src/lib/utils/events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { deriveFormattedTimestamp } from './date'

export function formatEventCTA(input: string): string {
if (input.toLowerCase() === 'rsvp') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this change, this function returned rsvp as Rsvp

return 'RSVP'
}

const words: string[] = input.split('_')

const formattedString: string = words
Expand Down
43 changes: 19 additions & 24 deletions src/templates/layouts/event/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export const Event = ({
.filter(Boolean)
.join(', ')

const eventCTAText = formatEventCTA(eventCTA)

return (
<div className="va-l-detail-page va-facility-page">
<div className="usa-grid usa-grid-full">
Expand Down Expand Up @@ -228,33 +230,26 @@ export const Event = ({
</p>
) : (
<>
{link && (
<p className="vads-u-margin--0">
<a className="vads-c-action-link--green" href={link?.uri}>
{eventCTA && eventCTA != 'more_details'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced the nested ternary with the formatEventCTA utility function which does the same thing.

? eventCTA.toLowerCase() === 'rsvp'
? eventCTA.toUpperCase()
: eventCTA.charAt(0).toUpperCase() + eventCTA.slice(1)
: 'More details'}
</a>
</p>
{link && eventCTAText && (
<va-link-action
class="vads-u-display--block"
href={link?.uri}
text={eventCTAText}
/>
)}
{howToSignUp === 'email' && (
<>
{mostRecentDate && (
<p className="vads-u-margin--0">
<a
className="vads-c-action-link--green"
href={createMailToLink(
emailCTA,
title,
mostRecentDate,
link?.uri
)}
>
{eventCTA && formatEventCTA(eventCTA)}
</a>
</p>
{mostRecentDate && eventCTAText && (
<va-link-action
class="vads-u-display--block"
href={createMailToLink(
emailCTA,
title,
mostRecentDate,
link?.uri
)}
text={eventCTAText}
/>
)}
</>
)}
Expand Down
Loading