-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: add campaign details page (#7531)
- Loading branch information
1 parent
fac70e4
commit e288b63
Showing
9 changed files
with
170 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\CampaignDetailsPage; | ||
|
||
/** | ||
* @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, | ||
'campaignDetailsPage' => (new CampaignDetailsPage($campaign))->exports(), | ||
] | ||
); | ||
|
||
wp_enqueue_script($handleName); | ||
wp_enqueue_style('givewp-design-system-foundation'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Give\Campaigns\ViewModels; | ||
|
||
use Give\Campaigns\Models\Campaign; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
class CampaignDetailsPage | ||
{ | ||
/** | ||
* @unreleased | ||
* | ||
* @var Campaign | ||
*/ | ||
protected $campaign; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function __construct(Campaign $campaign) | ||
{ | ||
$this->campaign = $campaign; | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function exports(): array | ||
{ | ||
return [ | ||
'overviewTab' => $this->campaign->toArray(), | ||
'settingsTab' => [ | ||
'landingPageUrl' => admin_url('?action=edit_campaign_page&campaign_id=' . $this->campaign->id), | ||
], | ||
'reportTab' => [], | ||
'updatesTab' => [], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {createRoot} from 'react-dom/client'; | ||
import CampaignsDetailsPage from './components/CampaignDetailsPage'; | ||
|
||
const container = document.getElementById('give-admin-campaigns-root'); | ||
const root = createRoot(container!); | ||
root.render(<CampaignsDetailsPage />); |
4 changes: 4 additions & 0 deletions
4
src/Campaigns/resources/admin/components/CampaignDetailsPage/CampaignDetailsPage.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.container { | ||
margin-top: 3rem; | ||
padding: 3rem; | ||
} |
52 changes: 52 additions & 0 deletions
52
src/Campaigns/resources/admin/components/CampaignDetailsPage/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import {GiveCampaignDetails} from './types'; | ||
import styles from './CampaignDetailsPage.module.scss'; | ||
|
||
declare const window: { | ||
GiveCampaignDetails: GiveCampaignDetails; | ||
} & Window; | ||
|
||
export function getGiveCampaignDetailsWindowData() { | ||
return window.GiveCampaignDetails; | ||
} | ||
|
||
const {campaignDetailsPage} = getGiveCampaignDetailsWindowData(); | ||
|
||
console.log(Object.values(campaignDetailsPage.overviewTab)); | ||
|
||
export default function CampaignsDetailsPage() { | ||
return ( | ||
<div className={styles.container}> | ||
<h1> | ||
<strong>Campaign details goes here...</strong> | ||
</h1> | ||
<p>Just below you can see a few data from the details page separated by tabs.</p> | ||
<br /> | ||
<h2> | ||
<strong>Overview Tab</strong> | ||
</h2> | ||
<ul> | ||
{Object.entries(campaignDetailsPage.overviewTab).map(([property, value], index) => ( | ||
<li key={index}> | ||
<span> | ||
<strong>{property}:</strong> {String(value)} | ||
</span> | ||
</li> | ||
))} | ||
</ul> | ||
<br /> | ||
<h2> | ||
<strong>Settings Tab</strong> | ||
</h2> | ||
<p> | ||
<a | ||
style={{fontSize: '1.5rem'}} | ||
href={campaignDetailsPage.settingsTab.landingPageUrl} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
Edit Campaign Landing Page ⭷ | ||
</a> | ||
</p> | ||
</div> | ||
); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Campaigns/resources/admin/components/CampaignDetailsPage/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export interface GiveCampaignDetails { | ||
apiRoot: string; | ||
apiNonce: string; | ||
adminUrl: string; | ||
pluginUrl: string; | ||
campaignDetailsPage: { | ||
overviewTab: any; | ||
settingsTab: { | ||
landingPageUrl: string; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters