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 create new campaign flow #7543

Merged
merged 20 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
44685d9
refactor: split form into two steps
glaubersilva Sep 17, 2024
ee4c906
feature: add upload cover image component
glaubersilva Sep 18, 2024
09c602a
refactor: change styles
glaubersilva Sep 18, 2024
fd643df
feature: add validation to first step
glaubersilva Sep 18, 2024
816e605
refactor: simplify logic for steps
glaubersilva Sep 18, 2024
8f942a1
Merge branch 'epic/campaigns' into feature/new-campaign-flow-GIVE-1217
glaubersilva Sep 23, 2024
834d032
feature: add goal options
glaubersilva Sep 24, 2024
2e8619f
refactor: add GoalTypeOption component
glaubersilva Sep 24, 2024
643c17c
chore: remove comment
glaubersilva Sep 24, 2024
e7e3bda
feature: add icon placeholder
glaubersilva Sep 24, 2024
c48c847
refactor: add icons, change class names and create goal component
glaubersilva Sep 25, 2024
b1cf799
refactor: remove Goal component and move GoalTypeOption component
glaubersilva Sep 25, 2024
ec8f6b1
refactor: move the upload component and tweak styles
glaubersilva Sep 25, 2024
fd294ab
refactor: rename component
glaubersilva Sep 26, 2024
1d56252
Merge branch 'epic/campaigns' into feature/new-campaign-flow-GIVE-1217
glaubersilva Sep 26, 2024
2987ed6
refactor: simplify goalInputAttributes logic
glaubersilva Sep 27, 2024
2a7b56a
refactor: change goal type
glaubersilva Sep 27, 2024
6c94921
refactor: add getGoalTypeIcon function
glaubersilva Sep 27, 2024
592794e
refactor: add GoalTypeOption
glaubersilva Sep 27, 2024
68704ac
refactor: change list table columns
glaubersilva Sep 27, 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
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
Loading