Skip to content

Commit

Permalink
Feature: add create new campaign flow (#7543)
Browse files Browse the repository at this point in the history
  • Loading branch information
glaubersilva authored Oct 1, 2024
1 parent da95ba6 commit 67011c2
Show file tree
Hide file tree
Showing 16 changed files with 882 additions and 109 deletions.
6 changes: 4 additions & 2 deletions src/Campaigns/Actions/LoadCampaignsListTableAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Give\Campaigns\Actions;

use Give\Campaigns\ListTable\CampaignsListTable;
use Give\Framework\Support\Facades\Scripts\ScriptAsset;

/**
* @unreleased
Expand All @@ -15,12 +16,13 @@ class LoadCampaignsListTableAssets
public function __invoke()
{
$handleName = 'givewp-admin-campaigns-list-table';
$asset = ScriptAsset::get(GIVE_PLUGIN_DIR . 'assets/dist/js/give-admin-campaigns-list-table.asset.php');

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

Expand Down
30 changes: 18 additions & 12 deletions src/Campaigns/ListTable/CampaignsListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Give\Campaigns\ListTable;

use Give\Campaigns\ListTable\Columns\DescriptionColumn;
use Give\Campaigns\ListTable\Columns\EndDateColumn;
use Give\Campaigns\ListTable\Columns\DonationsCountColumn;
use Give\Campaigns\ListTable\Columns\GoalColumn;
use Give\Campaigns\ListTable\Columns\IdColumn;
use Give\Campaigns\ListTable\Columns\StartDateColumn;
use Give\Campaigns\ListTable\Columns\NameColumn;
use Give\Campaigns\ListTable\Columns\RevenueColumn;
use Give\Campaigns\ListTable\Columns\StatusColumn;
use Give\Campaigns\ListTable\Columns\TitleColumn;
use Give\Framework\ListTable\ListTable;
use Give\Framework\ListTable\ModelColumn;

Expand All @@ -34,11 +34,14 @@ protected function getDefaultColumns(): array
// TODO We need to decide which columns should be displayed
return [
new IdColumn(),
new TitleColumn(),
new DescriptionColumn(),
new NameColumn(),
new GoalColumn(),
new DonationsCountColumn(),
new RevenueColumn(),
//new DescriptionColumn(),
//new DonationsCountColumn(),
new StartDateColumn(),
new EndDateColumn(),
//new StartDateColumn(),
//new EndDateColumn(),
new StatusColumn(),
];
}
Expand All @@ -52,11 +55,14 @@ protected function getDefaultVisibleColumns(): array
{
return [
IdColumn::getId(),
TitleColumn::getId(),
DescriptionColumn::getId(),
NameColumn::getId(),
GoalColumn::getId(),
DonationsCountColumn::getId(),
RevenueColumn::getId(),
//DescriptionColumn::getId(),
//DonationsCountColumn::getId(),
StartDateColumn::getId(),
EndDateColumn::getId(),
//StartDateColumn::getId(),
//EndDateColumn::getId(),
StatusColumn::getId(),
];
}
Expand Down
42 changes: 42 additions & 0 deletions src/Campaigns/ListTable/Columns/DateColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Give\Campaigns\ListTable\Columns;

use Give\Campaigns\Models\Campaign;
use Give\Framework\ListTable\ModelColumn;

/**
* @unreleased
*/
class DateColumn extends ModelColumn
{
protected $sortColumn = 'date';

/**
* @unreleased
*/
public static function getId(): string
{
return 'date';
}

/**
* @unreleased
*/
public function getLabel(): string
{
return __('Date', 'give');
}

/**
* @unreleased
*
* @param Campaign $model
*/
public function getCellValue($model, $locale = ''): string
{
$format = _x('m/d/Y \a\t g:ia', 'date format', 'give');

return $model->createdAt->format($format);
}
}
2 changes: 1 addition & 1 deletion src/Campaigns/ListTable/Columns/DonationsCountColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function getId(): string
*/
public function getLabel(): string
{
return __('Donations Count', 'give');
return __('Donations', 'give');
}

/**
Expand Down
40 changes: 40 additions & 0 deletions src/Campaigns/ListTable/Columns/GoalColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Give\Campaigns\ListTable\Columns;

use Give\Campaigns\Models\Campaign;
use Give\Framework\ListTable\ModelColumn;

/**
* @unreleased
*/
class GoalColumn extends ModelColumn
{
protected $sortColumn = 'goal';

/**
* @unreleased
*/
public static function getId(): string
{
return 'goal';
}

/**
* @unreleased
*/
public function getLabel(): string
{
return __('Goal', 'give');
}

/**
* @unreleased
*
* @param Campaign $model
*/
public function getCellValue($model): int
{
return $model->goal;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@
/**
* @unreleased
*/
class TitleColumn extends ModelColumn
class NameColumn extends ModelColumn
{
protected $sortColumn = 'title';
protected $sortColumn = 'name';

/**
* @unreleased
*/
public static function getId(): string
{
return 'title';
return 'name';
}

/**
* @unreleased
*/
public function getLabel(): string
{
return __('Title', 'give');
return __('Name', 'give');
}

/**
Expand Down
40 changes: 40 additions & 0 deletions src/Campaigns/ListTable/Columns/RevenueColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Give\Campaigns\ListTable\Columns;

use Give\Campaigns\Models\Campaign;
use Give\Framework\ListTable\ModelColumn;

/**
* @unreleased
*/
class RevenueColumn extends ModelColumn
{
protected $sortColumn = 'revenue';

/**
* @unreleased
*/
public static function getId(): string
{
return 'revenue';
}

/**
* @unreleased
*/
public function getLabel(): string
{
return __('Revenue', 'give');
}

/**
* @unreleased
*
* @param Campaign $model
*/
public function getCellValue($model): int
{
return 0;
}
}
32 changes: 24 additions & 8 deletions src/Campaigns/Routes/CreateCampaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,30 @@ public function registerRoute()
'required' => true,
'sanitize_callback' => 'sanitize_text_field',
],
'description' => [
'shortDescription' => [
'type' => 'string',
'required' => false,
'sanitize_callback' => 'sanitize_text_field',
],
'image' => [
'type' => 'string',
'required' => false,
'sanitize_callback' => 'sanitize_url',
],
'goalType' => [
'type' => 'string',
'required' => true,
'sanitize_callback' => 'sanitize_text_field',
],
'goal' => [
'type' => 'integer',
'required' => true,
'sanitize_callback' => 'absint',
],
'startDateTime' => [
'type' => 'string',
'format' => 'date-time', // @link https://datatracker.ietf.org/doc/html/rfc3339#section-5.8
'required' => true,
'required' => false,
'validate_callback' => 'rest_parse_date',
'sanitize_callback' => function ($value) {
return new DateTime($value);
Expand Down Expand Up @@ -78,17 +93,18 @@ public function handleRequest(WP_REST_Request $request): WP_REST_Response
{
$campaign = Campaign::create([
'type' => CampaignType::CORE(),
'title' => $request->get_param('title'),
'shortDescription' => $request->get_param('shortDescription'),
'title' => $request->get_param('title') ?? '',
'shortDescription' => $request->get_param('shortDescription') ?? '',
'longDescription' => '',
'logo' => '',
'image' => '',
'image' => $request->get_param('image') ?? '',
'primaryColor' => '',
'secondaryColor' => '',
'goal' => 0,
//'goalType' => $request->get_param('goalType') ?? '',
'goal' => $request->get_param('goal') ?? '',
'status' => CampaignStatus::DRAFT(),
'startDate' => $request->get_param('startDateTime'),
'endDate' => $request->get_param('endDateTime'),
'startDate' => $request->get_param('startDateTime') ?? null,
'endDate' => $request->get_param('endDateTime') ?? null,
]);

return new WP_REST_Response($campaign->toArray(), 201);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,89 @@
padding: var(--givewp-spacing-2) var(--givewp-spacing-4);
text-align: center;
}

input,
label {
font-size: 1rem;
}

.description {
font-size: 0.875rem;
margin-bottom: 0.4rem;
}
}

.fieldRequired {
color: var(--givewp-red-500);
}

.goalType {

.goalTypeOption {
margin: 0.5rem 0 0.5rem 0;
display: flex;
flex-direction: row;
align-items: center;
gap: 1rem;

cursor: pointer;
border: 1px solid #9CA0AF;
border-radius: 1rem;
padding: 0.75rem 1.5rem 0.75rem 1.5rem;
}

.goalTypeOptionIcon {

svg {
width: 2.5rem;
height: 2.5rem;
}

path {
stroke: #9CA0AF;
}
}

.goalTypeOptionText {

label,
span {
cursor: pointer;
}

span {
margin-top: 0.2rem;
display: inline-block;
line-height: 1rem !important;
}

/* Hide the radio button input */
input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
}

.goalTypeOptionSelected {
background-color: #374151;

.goalTypeOptionIcon {
svg path {
stroke: #F9FAFB;
}
}

.goalTypeOptionText {
label,
span {
color: #F9FAFB !important;
}
}
}
}



Loading

0 comments on commit 67011c2

Please sign in to comment.