Skip to content

Commit

Permalink
Import: better form
Browse files Browse the repository at this point in the history
  • Loading branch information
ilestis committed Nov 16, 2023
1 parent 66f9864 commit 3789ef3
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 7 deletions.
2 changes: 2 additions & 0 deletions app/Http/Controllers/Campaign/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Http\Controllers\Controller;
use App\Models\Campaign;
use App\Services\Campaign\Import\PrepareService;
use Exception;

class ImportController extends Controller
{
Expand Down Expand Up @@ -45,6 +46,7 @@ public function index(Campaign $campaign)
->user(auth()->user())
->token();


return view('campaigns.import.index')
->with('campaign', $campaign)
->with('token', $token)
Expand Down
5 changes: 5 additions & 0 deletions app/Models/CampaignImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public function user()
return $this->belongsTo(User::class);
}

public function isPrepared(): bool
{
return $this->status_id == CampaignImportStatus::PREPARED;
}

public function isFailed(): bool
{
return $this->status_id == CampaignImportStatus::FAILED;
Expand Down
2 changes: 1 addition & 1 deletion app/Services/Campaign/Import/PrepareService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function token(): CampaignImport
{
$token = CampaignImport::where('campaign_id', $this->campaign->id)
->where('user_id', $this->user->id)
->where('status_id', CampaignImportStatus::PREPARED)
->whereNotIn('status_id', [CampaignImportStatus::FINISHED, CampaignImportStatus::FAILED])
->first();
if ($token) {
return $token;
Expand Down
1 change: 1 addition & 0 deletions public/build/assets/import-32d5882e.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion public/build/assets/import-9d98db56.js

This file was deleted.

2 changes: 1 addition & 1 deletion public/build/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"src": "resources/js/billing.js"
},
"resources/js/campaigns/import.js": {
"file": "assets/import-9d98db56.js",
"file": "assets/import-32d5882e.js",
"imports": [
"_index-0b481a1e.js",
"__commonjsHelpers-725317a4.js"
Expand Down
7 changes: 3 additions & 4 deletions resources/js/campaigns/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const initExport = () => {
};

const startProcess = (form, data) => {
console.log('start');
form.classList.add('hidden');

// Now upload to the real endpoint
let config = {
Expand All @@ -66,15 +66,14 @@ const startProcess = (form, data) => {
axios
.post(form.action, data, config)
.then(function (res) {
console.log('yo?');
fileProgress.hide();

if (res.data.success) {

window.location.reload();
}
})
.catch(function (err) {
alert('oops');
form.classList.remove('hidden');
fileProgress.hide();

if (err.response && err.response.data.message) {
Expand Down
2 changes: 2 additions & 0 deletions resources/views/campaigns/import/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
</a>
</div>

@if ($token->isPrepared())
<form id="campaign-import-form" method="post" action="{{ \App\Facades\Domain::importer() }}">
{{ csrf_field() }}
<x-grid type="1/1">
Expand Down Expand Up @@ -51,6 +52,7 @@
<span class="sr-only"></span>
</div>
</div>
@endif

<div class="box box-solid">
<div id="datagrid-parent" class="table-responsive">
Expand Down

0 comments on commit 3789ef3

Please sign in to comment.