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

GP 623: Revert sprintf so logged out rsvp functionality works #633

Closed
wants to merge 4 commits into from

Conversation

jmarx
Copy link
Collaborator

@jmarx jmarx commented Mar 31, 2024

Description of the Change

Removing sprintf so the logged out version of the RSVP block functions properly

Closes #623

How to test the Change

Try to RSVP to an event when logged out and ensure the log/register links work properly.

Screenshot 2024-03-31 at 11 37 37 AM

Changelog Entry

Fixed - Bug fix

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.

@carstingaxion
Copy link
Collaborator

OK, this took me a while, but yeah.

Bildschirmaufzeichnung.vom.01.04.2024.00.53.49.mp4

@carstingaxion
Copy link
Collaborator

Given the JS, I added originally some weeks ago:

{HtmlReactParser(
	sprintf(
		/* translators: %s: 'Login' (hyperlinked) */
		__(
			'You must %s to RSVP to events.',
			'gatherpress'
		),
		<a href={getFromGlobal('urls.loginUrl')}>
			{_x(
				'Login',
				'Context: You must ~ to RSVP to events.',
				'gatherpress'
			)}
		</a>
	)
)}

What I did not take into account, is that the <a> tag is going to be read as <react> component, not as a string, like sprintf expects. That resulted in the described error.

The easy fix took me a while, but it's just and only some nice little backticks.

{HtmlReactParser(
	sprintf(
		/* translators: %s: 'Login' (hyperlinked) */
		__(
			'You must %s to RSVP to events.',
			'gatherpress'
		),
		`<a href=${getFromGlobal('urls.loginUrl')}>
			${_x(
				'Login', 
				'Context: You must ~ to RSVP to events.', 
				'gatherpress'
			)}
		</a>`
	)
)}

Since React v17, Native 0.68 you can also just use curly braces inside of backticks: ${integerToString}. This will convert your embedded value to string.

People out there even created npm packages to solve this.

@carstingaxion
Copy link
Collaborator

I would suggest closing this in favor of #634

Best regards.

@jmarx jmarx closed this Apr 1, 2024
@jmarx jmarx deleted the GP-623 branch April 1, 2024 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Login Required modal has [object Object] as text
2 participants