Skip to content

Commit

Permalink
Merge pull request #959 from bakaphp/hotfix-new-lead
Browse files Browse the repository at this point in the history
Merge pull request #916 from bakaphp/development
  • Loading branch information
kaioken authored Feb 19, 2024
2 parents 48fcf7f + f80e09a commit e9b87b2
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 7 deletions.
3 changes: 3 additions & 0 deletions app/GraphQL/Ecosystem/Mutations/Users/Invite.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\GraphQL\Ecosystem\Mutations\Users;

use Kanvas\Apps\Models\Apps;
use Kanvas\Users\Actions\CreateInviteAction;
use Kanvas\Users\Actions\ProcessInviteAction;
use Kanvas\Users\DataTransferObject\CompleteInviteInput;
Expand All @@ -25,8 +26,10 @@ class Invite
public function insertInvite($rootValue, array $request): UsersInvite
{
$request = $request['input'];
$app = app(Apps::class);
$invite = new CreateInviteAction(
new InviteDto(
$app,
$request['companies_branches_id'],
$request['role_id'],
$request['email'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ public function insertInvite($rootValue, array $request): UsersInvite
{
$request = $request['input'];
$company = auth()->user()->getCurrentCompany();
$app = app(Apps::class);

$invite = new CreateInviteAction(
new InviteDto(
$app,
$request['companies_branches_id'] ?? auth()->user()->getCurrentBranch()->getId(),
$request['role_id'] ?? RolesRepository::getByNameFromCompany(RolesEnums::USER->value, $company)->id,
$request['email'],
Expand Down
9 changes: 6 additions & 3 deletions src/Domains/Connectors/Zoho/DataTransferObject/ZohoLead.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public function __construct(
public static function fromLead(Lead $lead): self
{
$customFields = $lead->getAll();
$companyZohoMapFields = $lead->company()->first()->get(CustomFieldEnum::FIELDS_MAP->value);
$company = $lead->company()->first();
$companyZohoMapFields = $company->get(CustomFieldEnum::FIELDS_MAP->value);

$additionalFields = [];
if ($companyZohoMapFields && is_array($companyZohoMapFields)) {
Expand All @@ -38,8 +39,10 @@ public static function fromLead(Lead $lead): self
}

$people = $lead->people()->first();
$owner = (string) ($lead->owner()->first() ? $lead->company()->first()->get(CustomFieldEnum::DEFAULT_OWNER->value) : null);
$status = (string) ($lead->status()->first() ? $lead->status()->first()->get(CustomFieldEnum::ZOHO_STATUS_NAME->value) : 'New Lead');
$leadStatus = $lead->status()->first();
$owner = (string) ($lead->owner()->first() ? $company->get(CustomFieldEnum::DEFAULT_OWNER->value) : null);
$newLead = 'New Lead';
$status = $leadStatus ? ($leadStatus->get(CustomFieldEnum::ZOHO_STATUS_NAME->value) ?? $newLead) : $newLead;

return new self(
$people->firstname,
Expand Down
2 changes: 1 addition & 1 deletion src/Kanvas/Enums/AppEnums.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function getValue(): mixed
self::KANVAS_APP_BRANCH_HEADER => 'X-Kanvas-Location',
self::KANVAS_APP_COMPANY_AUTH_HEADER => 'Company-Authorization', //@deprecated
self::DISPLAYNAME_LOGIN => 'displayname_login',
self::VERSION => '1.0-BETA-22',
self::VERSION => '1.0-BETA-21',
self::ANONYMOUS_USER_ID => -1
};
}
Expand Down
2 changes: 2 additions & 0 deletions src/Kanvas/Enums/AppSettingsEnums.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum AppSettingsEnums implements EnumsInterface
case ONE_SIGNAL_REST_API_KEY;
case PASSWORD_STRENGTH;
case DEFAULT_SIGNUP_ROLE;
case INVITE_EMAIL_SUBJECT;

/**
* Get value.
Expand All @@ -41,6 +42,7 @@ public function getValue(): mixed
self::ONE_SIGNAL_REST_API_KEY => 'one_signal_rest_api_key',
self::PASSWORD_STRENGTH => 'flag_password_strength',
self::DEFAULT_SIGNUP_ROLE => 'default_signup_role',
self::INVITE_EMAIL_SUBJECT => 'invite_email_subject',
};
}
}
9 changes: 6 additions & 3 deletions src/Kanvas/Users/Actions/CreateInviteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Str;
use Kanvas\AccessControlList\Repositories\RolesRepository;
use Kanvas\Apps\Models\Apps;
use Kanvas\Companies\Models\CompaniesBranches;
use Kanvas\Companies\Repositories\CompaniesRepository;
use Kanvas\Enums\AppSettingsEnums;
use Kanvas\Notifications\Templates\Invite as InviteTemplate;
use Kanvas\Users\DataTransferObject\Invite as InviteDto;
use Kanvas\Users\Models\Users;
Expand Down Expand Up @@ -50,7 +50,7 @@ public function execute(): UsersInvite
'companies_id' => $company->getKey(),
'companies_branches_id' => $companyBranch->getKey(),
'role_id' => $this->inviteDto->role_id,
'apps_id' => app(Apps::class)->getKey(),
'apps_id' => $this->inviteDto->app->getId(),
'email' => $this->inviteDto->email,
'firstname' => $this->inviteDto->firstname,
'lastname' => $this->inviteDto->lastname,
Expand All @@ -69,9 +69,12 @@ public function execute(): UsersInvite
'default_company_branch' => $companyBranch->getId(),
]);
*/
//@todo allow it to be customized
$emailTitle = $this->inviteDto->app->get(AppSettingsEnums::INVITE_EMAIL_SUBJECT->getValue()) ?? 'You\'ve been invited to join ' . $company->name;

$inviteEmail = new InviteTemplate($invite, [
'fromUser' => $this->user,
'subject' => 'You have been invited to join ' . $company->name,
'subject' => $emailTitle,
'template' => $this->inviteDto->email_template,
'company' => $company,
]);
Expand Down
2 changes: 2 additions & 0 deletions src/Kanvas/Users/DataTransferObject/Invite.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Kanvas\Users\DataTransferObject;

use Baka\Contracts\AppInterface;
use Spatie\LaravelData\Data;

class Invite extends Data
Expand All @@ -13,6 +14,7 @@ class Invite extends Data
* @todo move to camel case
**/
public function __construct(
public AppInterface $app,
public int $companies_branches_id,
public int $role_id,
public string $email,
Expand Down

0 comments on commit e9b87b2

Please sign in to comment.