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

Feature: Add campaign title block #7648

Open
wants to merge 14 commits into
base: epic/campaigns
Choose a base branch
from

Conversation

pauloiankoski
Copy link
Contributor

@pauloiankoski pauloiankoski commented Dec 12, 2024

Resolves GIVE-1959

Description

This pull request lays the foundation for future Campaign-related blocks by introducing key structural elements. The updates in this PR include:

  • Dynamic Block Registration: Registers blocks dynamically based on their block.json files.
  • Campaign Page REST API: Adds campaignId as a field to the REST API response for the Campaign Page CPT.
  • Custom Hooks and Shared Components: Introduces reusable hooks and components to simplify campaign selection or retrieval from context within campaign blocks.
  • Initial Campaign Title Block: Adds a basic Campaign Title block to serve as a reference and model for upcoming blocks.

These changes establish a scalable and flexible structure for Campaign blocks, enabling more streamlined development of future features.

Visuals

CleanShot 2024-12-12 at 11 30 34

Testing Instructions

  1. Test on a Campaign Page:
  • Open a Campaign Page.
  • Add the Campaign Title block.
  • Verify that the block renders automatically, displaying the corresponding campaign title.
  1. Test on Other Pages:
  • Open any other page type (not a Campaign Page).
  • Add the Campaign Title block.
  • Ensure that a campaign selector is displayed.
  • Select a campaign from the selector.
  • Verify that the block updates and renders the title of the selected campaign.

Pre-review Checklist

  • Acceptance criteria satisfied and marked in related issue
  • Relevant @unreleased tags included in DocBlocks
  • Includes unit tests
  • Reviewed by the designer (if follows a design)
  • Self Review of code and UX completed

Copy link
Contributor

@glaubersilva glaubersilva left a comment

Choose a reason for hiding this comment

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

@pauloiankoski I'm trying to compile it with npm run dev but I'm receiving multiple errors in the console as you can see here:

ERROR in C:\Users\glaub\Local Sites\givewp\app\public\wp-content\plugins\give\src\Campaigns\Blocks\CampaignTitleBlock\edit.tsx
23:35-42
[tsl] ERROR in C:\Users\glaub\Local Sites\givewp\app\public\wp-content\plugins\give\src\Campaigns\Blocks\CampaignTitleBlock\edit.tsx(23,36)
      TS2339: Property 'getSite' does not exist on type 'never'.

ERROR in C:\Users\glaub\Local Sites\givewp\app\public\wp-content\plugins\give\src\Campaigns\Blocks\shared\hooks\useCampaignId.ts
5:47-65
[tsl] ERROR in C:\Users\glaub\Local Sites\givewp\app\public\wp-content\plugins\give\src\Campaigns\Blocks\shared\hooks\useCampaignId.ts(5,48)
      TS2339: Property 'getCurrentPostType' does not exist on type 'never'.

ERROR in C:\Users\glaub\Local Sites\givewp\app\public\wp-content\plugins\give\src\Campaigns\Blocks\shared\hooks\useCampaignId.ts
8:41-63
[tsl] ERROR in C:\Users\glaub\Local Sites\givewp\app\public\wp-content\plugins\give\src\Campaigns\Blocks\shared\hooks\useCampaignId.ts(8,42)
      TS2339: Property 'getEditedPostAttribute' does not exist on type 'never'.

Any idea?

P.S.: I already removed the node_modules folder and ran the npm install again just to make sure.

npm-dev-errors

@pauloiankoski
Copy link
Contributor Author

@glaubersilva We might need to add ts-ignore to all those errors since they are part of the internal data API.

@glaubersilva
Copy link
Contributor

glaubersilva commented Jan 13, 2025

@pauloiankoski Thanks for the update! I was able to compile it and see the block working on the campaign page. However, when I created a new regular page and added the block, I wasn't able to select a campaign because the selector only displayed the "No campaigns found" message.

image

One more thing I would like to clarify about the page title of the campaign page (CPT).

Is the expected behavior to display the string "No title" and prevent users from editing it?

image

@pauloiankoski
Copy link
Contributor Author

The "No campaign found" message is regarding an issue with our Campaign API endpoint.

CleanShot 2025-01-13 at 17 42 31

We have discussed about that but maybe it has not been tackled.

@pauloiankoski
Copy link
Contributor Author

The issue with the title is something to be addressed in a separated task where we may be syncing the Campaign title with the landing page title.

Copy link
Contributor

@glaubersilva glaubersilva left a comment

Choose a reason for hiding this comment

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

@pauloiankoski I did the first round of reviews and left a few comments with some suggestions. Tomorrow I'll do another round.

wordpress-scripts-webpack.config.js Outdated Show resolved Hide resolved
src/Campaigns/Actions/RegisterCampaignBlocks.php Outdated Show resolved Hide resolved
{hasResolved && campaign && (
<InspectorControls>
<PanelBody title="Settings" initialOpen={true}>
<BaseControl label="Title">
Copy link
Contributor

Choose a reason for hiding this comment

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

The BaseControl component requires an id attribute.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/WordPress/gutenberg/blob/trunk/packages/components/src/base-control/README.md#id

Per the docs, the only required attribute is children. Anyway, added here: 817d364

Copy link
Contributor

Choose a reason for hiding this comment

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

The weird thing is that the IDE says it's required.

image

src/Campaigns/Blocks/CampaignTitleBlock/edit.tsx Outdated Show resolved Hide resolved
src/Campaigns/Blocks/CampaignTitleBlock/edit.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@glaubersilva glaubersilva left a comment

Choose a reason for hiding this comment

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

@pauloiankoski Nice work! I left just a few more comments in my second round of reviews. As a note, I was a bit picky with the details while reviewing the code, as this is the first block that will serve as the foundation for others so I was trying to make sure we'll have a solid base for the next blocks. Thanks in advance for your understanding. 🙂

src/Campaigns/Blocks/CampaignTitleBlock/render.php Outdated Show resolved Hide resolved
src/Campaigns/Blocks/shared/hooks/useCampaign.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@glaubersilva glaubersilva left a comment

Choose a reason for hiding this comment

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

@pauloiankoski Thanks for the changes, great work man! 🚀

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.

2 participants