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 details page header with tabs, save buttons, and form with sample input #7536

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
50a14c4
feature: add initial header with tabs
glaubersilva Sep 12, 2024
01da9c0
Merge branch 'epic/campaigns' into feature/campaigns-details-header-G…
glaubersilva Sep 12, 2024
436669c
refactor: change tab options logic
glaubersilva Sep 12, 2024
01ca995
fix: wp-link-wrap z-index
glaubersilva Sep 13, 2024
0ea7e12
feature: add routing and navigation logic for tabs
glaubersilva Sep 13, 2024
e6aa6af
refactor: extract campaign tabs array to a separate file
glaubersilva Sep 13, 2024
f3938d0
refactor: rename type and const
glaubersilva Sep 13, 2024
d3ef5fd
refactor: change tabs and button styles
glaubersilva Sep 13, 2024
5bf8081
feature: add routes for the update button
glaubersilva Sep 13, 2024
54023a1
feature: add "save as draft" button
glaubersilva Sep 13, 2024
fd23d20
feature: add form provider
glaubersilva Sep 16, 2024
27a00de
feature: add status classes
glaubersilva Sep 16, 2024
3de7904
refactor: move status classes
glaubersilva Sep 16, 2024
70e8d3b
refactor: use react-aria-components for tabs
glaubersilva Sep 19, 2024
d458f98
refactor: change handleTabNavigation parameter
glaubersilva Sep 19, 2024
68a9853
refactor: simplify handleTabNavigation logic
glaubersilva Sep 19, 2024
c4f87ac
refactor: css tweaks
glaubersilva Sep 19, 2024
d362f6f
refactor: simplify UpdateCampaign logic
glaubersilva Sep 20, 2024
7f6062c
refactor: simplify PublishCampaign logic
glaubersilva Sep 20, 2024
d465a37
refactor: change status and methods
glaubersilva Sep 20, 2024
7f64906
refactor: remove RestResponses trait
glaubersilva Sep 20, 2024
ea7a3d1
refactor: remove trait import
glaubersilva Sep 20, 2024
849de72
refactor: change endpoint
glaubersilva Sep 20, 2024
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
8 changes: 5 additions & 3 deletions src/Campaigns/Actions/LoadCampaignDetailsAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Give\Campaigns\Models\Campaign;
use Give\Campaigns\ViewModels\CampaignDetailsPage;
use Give\Framework\Support\Facades\Scripts\ScriptAsset;

/**
* @unreleased
Expand All @@ -16,12 +17,13 @@ class LoadCampaignDetailsAssets
public function __invoke(Campaign $campaign)
{
$handleName = 'givewp-admin-campaign-details';
$asset = ScriptAsset::get(GIVE_PLUGIN_DIR . 'assets/dist/js/give-admin-campaign-details.asset.php');

wp_register_script(
$handleName,
GIVE_PLUGIN_URL . 'assets/dist/js/give-admin-campaign-details.js',
[],
GIVE_VERSION,
$asset['dependencies'],
$asset['version'],
true
);

Expand All @@ -31,7 +33,7 @@ public function __invoke(Campaign $campaign)
'apiNonce' => wp_create_nonce('wp_rest'),
'adminUrl' => admin_url(),
'pluginUrl' => GIVE_PLUGIN_URL,
'campaignDetailsPage' => (new CampaignDetailsPage($campaign))->exports(),
'campaign' => (new CampaignDetailsPage($campaign))->exports(),
]
);

Expand Down
69 changes: 69 additions & 0 deletions src/Campaigns/Routes/PublishCampaign.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace Give\Campaigns\Routes;

use Exception;
use Give\API\RestRoute;
use Give\Campaigns\Models\Campaign;
use Give\Campaigns\ValueObjects\CampaignStatus;
use WP_REST_Request;
use WP_REST_Response;
use WP_REST_Server;

/**
* @unreleased
*/
class PublishCampaign implements RestRoute
{

/** @var string */
protected $endpoint = 'campaigns/(?P<id>[0-9]+)/publish';

/** @var Campaign */
protected $campaign;

/**
* @unreleased
*/
public function registerRoute()
{
register_rest_route(
'give-api/v2',
$this->endpoint,
[
[
'methods' => WP_REST_Server::EDITABLE,
'callback' => [$this, 'handleRequest'],
'permission_callback' => function () {
return current_user_can('manage_options');
},
],
'args' => [
'id' => [
'type' => 'string',
'required' => true,
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => function ($id) {
return $this->campaign = Campaign::find($id);
},
],
],
]
);
}

/**
* @unreleased
*
* @throws Exception
*/
public function handleRequest(WP_REST_Request $request): WP_Rest_Response
{
$this->campaign->status = CampaignStatus::ACTIVE();
$this->campaign->save();

$response = json_encode($this->campaign->toArray());

return new WP_REST_Response($response, 200);
}
}
77 changes: 77 additions & 0 deletions src/Campaigns/Routes/UpdateCampaign.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace Give\Campaigns\Routes;

use Exception;
use Give\API\RestRoute;
use Give\Campaigns\Models\Campaign;
use WP_REST_Request;
use WP_REST_Response;
use WP_REST_Server;

/**
* @unreleased
*/
class UpdateCampaign implements RestRoute
{

/** @var string */
protected $endpoint = 'campaigns/(?P<id>[0-9]+)';

/** @var Campaign */
protected $campaign;

public function registerRoute()
{
register_rest_route(
'give-api/v2',
$this->endpoint,
[
[
'methods' => WP_REST_Server::EDITABLE,
'callback' => [$this, 'handleRequest'],
'permission_callback' => function () {
return current_user_can('manage_options');
},
],
'args' => [
'id' => [
'type' => 'string',
'required' => true,
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => function ($id) {
return $this->campaign = Campaign::find($id);
},
],
'title' => [
'type' => 'string',
'required' => false,
'sanitize_callback' => 'sanitize_text_field',
],
],
]
);
}

/**
* @unreleased
*
* @throws Exception
*/
public function handleRequest(WP_REST_Request $request): WP_REST_Response
{
foreach ($request->get_params() as $key => $value) {
if ('id' !== $key) {
$this->campaign->setAttribute($key, $value);
}
}

if ($this->campaign->isDirty()) {
$this->campaign->save();
}

$response = json_encode($this->campaign->toArray());

return new WP_REST_Response($response, 200);
}
}
2 changes: 2 additions & 0 deletions src/Campaigns/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public function boot(): void
private function registerRoutes()
{
Hooks::addAction('rest_api_init', Routes\CreateCampaign::class, 'registerRoute');
Hooks::addAction('rest_api_init', Routes\PublishCampaign::class, 'registerRoute');
Hooks::addAction('rest_api_init', Routes\UpdateCampaign::class, 'registerRoute');
Hooks::addAction('rest_api_init', Routes\GetCampaignsListTable::class, 'registerRoute');
Hooks::addAction('rest_api_init', Routes\DeleteCampaignListTable::class, 'registerRoute');
}
Expand Down
6 changes: 2 additions & 4 deletions src/Campaigns/ViewModels/CampaignDetailsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ public function __construct(Campaign $campaign)
public function exports(): array
{
return [
'overviewTab' => $this->campaign->toArray(),
'settingsTab' => [
'properties' => $this->campaign->toArray(),
'settings' => [
'landingPageUrl' => admin_url('?action=edit_campaign_page&campaign_id=' . $this->campaign->id),
],
'reportTab' => [],
'updatesTab' => [],
];
}
}
Loading
Loading