-
Notifications
You must be signed in to change notification settings - Fork 192
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 setting for default form #7614
base: epic/campaigns
Are you sure you want to change the base?
Changes from all commits
bb51c53
592e74f
3f0e276
2732910
5cddc0a
0bea8ff
f50c964
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Give\Campaigns\DataTransferObjects; | ||
|
||
use Give\Campaigns\Models\Campaign; | ||
use Give\Framework\Support\Contracts\Arrayable; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
class CampaignDetailsData implements Arrayable | ||
{ | ||
/** | ||
* @var Campaign | ||
*/ | ||
private $campaign; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function __construct(Campaign $campaign) | ||
{ | ||
$this->campaign = $campaign; | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return array_merge( | ||
$this->campaign->toArray(), | ||
[ | ||
'defaultFormId' => $this->campaign->defaultForm()->id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we don't need this DTO since the campaign model will have the default form ID available when this PR is merged: #7616 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I'm looking at #7616 now. |
||
] | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -231,7 +231,7 @@ public function getSchema(): array | |
'description' => esc_html__('Campaign goal type', 'give'), | ||
], | ||
'defaultFormId' => [ | ||
'type' => 'integer', | ||
'type' => 'number', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is any specific reason to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understanding is that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kjohnson In this case, I think the best approach is to create a |
||
'description' => esc_html__('Default campaign form ID', 'give'), | ||
], | ||
], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,25 @@ | ||
import {__} from "@wordpress/i18n"; | ||
import HeaderText from './HeaderText'; | ||
import HeaderSubText from './HeaderSubText'; | ||
import {CampaignFormOption} from "@givewp/campaigns/admin/components/CampaignDetailsPage/types"; | ||
import {GiveCampaignDetails} from "@givewp/campaigns/admin/components/CampaignDetailsPage/types"; | ||
import {useFormContext} from "react-hook-form"; | ||
|
||
declare const window: { | ||
GiveCampaignDetails: GiveCampaignDetails; | ||
} & Window; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
const DefaultFormWidget = ({defaultForm}: {defaultForm: string}) => { | ||
const DefaultFormWidget = () => { | ||
|
||
const {watch} = useFormContext(); | ||
|
||
const [defaultFormId] = watch(['defaultFormId']); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason to not use the From the docs about watch
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would probably work. I had copy/pasted from another part of the codebase, but I'll refactor and try it. |
||
|
||
const defaultFormTitle = window.GiveCampaignDetails.donationForms | ||
.find(form => Number(form.id) === Number(defaultFormId))?.title; | ||
|
||
return ( | ||
<div style={{ | ||
flex: 1, | ||
|
@@ -46,7 +59,7 @@ const DefaultFormWidget = ({defaultForm}: {defaultForm: string}) => { | |
padding: '12px 16px', | ||
borderRadius: '4px', | ||
}}> | ||
{defaultForm} | ||
{defaultFormTitle} | ||
</div> | ||
</div> | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a way to load this form list beyond the first page load because it can get inaccurate easily depending of how user add new forms to the campaign - check my attached video for more details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is a list of forms available for re-use from the Campaign Forms List Table?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kjohnson I don't know if our List Table component provides some way to access the list of available items through a JS object or something like that, but I think not, even because the list table can have pagination which makes me think again that this field to update the default form trough the settings tab is not a good idea because in situations where we have a massive amount of forms in a single campaign, populate this dropdown can become a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we already have a registered
campaign
entity, we should use theuseEntityRecord
hook. As I see it, we should just update theCampaignDetailsData
DTO to include the forms associated with the campaign.