Skip to content

Commit

Permalink
feature: add overview page foundation
Browse files Browse the repository at this point in the history
  • Loading branch information
glaubersilva committed Sep 3, 2024
1 parent 1da2e15 commit 9f7f39e
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 1 deletion.
41 changes: 41 additions & 0 deletions src/Campaigns/Actions/LoadCampaignDetailsAssets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Give\Campaigns\Actions;

use Give\Campaigns\Models\Campaign;
use Give\Campaigns\ViewModels\CampaignDetails;

/**
* @unreleased
*/
class LoadCampaignDetailsAssets
{
/**
* @unreleased
*/
public function __invoke(Campaign $campaign)
{
$handleName = 'givewp-admin-campaign-details';

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

wp_localize_script($handleName, 'GiveCampaignDetails',
[
'apiRoot' => esc_url_raw(rest_url('give-api/v2/campaigns')),
'apiNonce' => wp_create_nonce('wp_rest'),
'adminUrl' => admin_url(),
'pluginUrl' => GIVE_PLUGIN_URL,
'campaign' => (new CampaignDetails($campaign))->exports(),
]
);

wp_enqueue_script($handleName);
wp_enqueue_style('givewp-design-system-foundation');
}
}
14 changes: 13 additions & 1 deletion src/Campaigns/CampaignsAdminPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Give\Campaigns;

use Give\Campaigns\Actions\LoadCampaignDetailsAssets;
use Give\Campaigns\Actions\LoadCampaignsListTableAssets;
use Give\Campaigns\Models\Campaign;

/**
* @unreleased
Expand Down Expand Up @@ -30,7 +32,17 @@ public function addCampaignsSubmenuPage()
*/
public function renderCampaignsPage()
{
give(LoadCampaignsListTableAssets::class)();
if (isset($_GET['id'])) {
$campaign = Campaign::find(absint($_GET['id']));

if ( ! $campaign) {
wp_die(__('Campaign not found', 'give'), 404);
}

give(LoadCampaignDetailsAssets::class)($campaign);
} else {
give(LoadCampaignsListTableAssets::class)();
}

echo '<div id="give-admin-campaigns-root"></div>';
}
Expand Down
34 changes: 34 additions & 0 deletions src/Campaigns/ViewModels/CampaignDetails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Give\Campaigns\ViewModels;

use Give\Campaigns\Models\Campaign;

/**
* @unreleased
*/
class CampaignDetails
{
/**
* @unreleased
*
* @var Campaign
*/
protected $campaign;

/**
* @unreleased
*/
public function __construct(Campaign $campaign)
{
$this->campaign = $campaign;
}

/**
* @unreleased
*/
public function exports(): array
{
return $this->campaign->toArray();
}
}
11 changes: 11 additions & 0 deletions src/Campaigns/resources/admin/campaign-details.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {createRoot} from 'react-dom/client';

const container = document.getElementById('give-admin-campaigns-root');
const root = createRoot(container!);
root.render(
<div style={{marginTop: '6rem', padding: '1rem'}}>
<p>
<strong>Campaign details goes here...</strong>
</p>
</div>
);
1 change: 1 addition & 0 deletions webpack.mix.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ mix.setPublicPath('assets/dist')
.ts('src/Promotions/InPluginUpsells/resources/js/payment-gateway.ts', 'js/payment-gateway.js')
.ts('src/Promotions/WelcomeBanner/resources/js/index.tsx', 'js/welcome-banner.js')
.ts('src/Campaigns/resources/admin/campaigns-list-table.tsx', 'js/give-admin-campaigns-list-table.js')
.ts('src/Campaigns/resources/admin/campaign-details.tsx', 'js/give-admin-campaign-details.js')

.react()
.sourceMaps(false, 'source-map')
Expand Down

0 comments on commit 9f7f39e

Please sign in to comment.