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 Convert Event CTAs to DS action links #853

Merged
merged 1 commit into from
Dec 20, 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
8 changes: 8 additions & 0 deletions src/lib/utils/events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { deriveFormattedTimestamp } from './date'

export function formatEventCTA(input: string): string {
if (!input) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extra null check here; but this function should not be called if the input is falsey.

return
}

if (input.toLowerCase() === 'rsvp') {
return 'RSVP'
}

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

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

let eventCTAText = null

if (eventCTA) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the change from last time; we didn't have a falsey check for eventCTA

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 +234,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'
? 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