diff --git a/app/Http/Controllers/Campaign/ImportController.php b/app/Http/Controllers/Campaign/ImportController.php index 6010a49a2e..04045e0c5b 100644 --- a/app/Http/Controllers/Campaign/ImportController.php +++ b/app/Http/Controllers/Campaign/ImportController.php @@ -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 { @@ -45,6 +46,7 @@ public function index(Campaign $campaign) ->user(auth()->user()) ->token(); + return view('campaigns.import.index') ->with('campaign', $campaign) ->with('token', $token) diff --git a/app/Models/CampaignImport.php b/app/Models/CampaignImport.php index ea315a3de0..0d41d3ad46 100644 --- a/app/Models/CampaignImport.php +++ b/app/Models/CampaignImport.php @@ -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; diff --git a/app/Services/Campaign/Import/PrepareService.php b/app/Services/Campaign/Import/PrepareService.php index 418e79602f..260e2463a8 100644 --- a/app/Services/Campaign/Import/PrepareService.php +++ b/app/Services/Campaign/Import/PrepareService.php @@ -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; diff --git a/public/build/assets/import-32d5882e.js b/public/build/assets/import-32d5882e.js new file mode 100644 index 0000000000..2fa39b1243 --- /dev/null +++ b/public/build/assets/import-32d5882e.js @@ -0,0 +1 @@ +import{a as d}from"./index-0b481a1e.js";import"./_commonjsHelpers-725317a4.js";$(document).ready(function(){c()});var n;const c=()=>{let t=document.getElementById("campaign-import-form");t&&(n=$(".progress"),t.onsubmit=s=>{s.preventDefault();let a=0,e=new FormData,o=document.getElementById("export-files");console.log("files",o.files),Array.from(o.files).forEach(i=>{i.name.endsWith(".zip")&&(a++,e.append("files[]",i))});let l=document.querySelector('input[name="campaign"]');e.append("campaign",l.value);let r=document.querySelector('input[name="token"]');if(e.append("token",r.value),a>0&&a<2)p(t,e);else return alert("Please select the campaign export zip files."),document.querySelector(".loading").classList.remove("loading"),!1})},p=(t,s)=>{t.classList.add("hidden");let a={headers:{"Content-Type":"multipart/form-data"},onUploadProgress:function(e){let o=Math.round(e.loaded*100/e.total);$('[role="progressbar"]').css("width",o+"%")}};n.show(),d.post(t.action,s,a).then(function(e){n.hide(),e.data.success&&window.location.reload()}).catch(function(e){if(t.classList.remove("hidden"),n.hide(),e.response&&e.response.data.message){fileError.text(e.response.data.message).fadeToggle();let o=e.response.data.errors;Object.keys(o).forEach(r=>{window.showToast(o[r],"error")})}})}; diff --git a/public/build/assets/import-9d98db56.js b/public/build/assets/import-9d98db56.js deleted file mode 100644 index efa952347b..0000000000 --- a/public/build/assets/import-9d98db56.js +++ /dev/null @@ -1 +0,0 @@ -import{a as c}from"./index-0b481a1e.js";import"./_commonjsHelpers-725317a4.js";$(document).ready(function(){d()});var r;const d=()=>{let t=document.getElementById("campaign-import-form");t&&(r=$(".progress"),t.onsubmit=n=>{n.preventDefault();let a=0,e=new FormData,o=document.getElementById("export-files");console.log("files",o.files),Array.from(o.files).forEach(l=>{l.name.endsWith(".zip")&&(a++,e.append("files[]",l))});let i=document.querySelector('input[name="campaign"]');e.append("campaign",i.value);let s=document.querySelector('input[name="token"]');if(e.append("token",s.value),a>0&&a<2)p(t,e);else return alert("Please select the campaign export zip files."),document.querySelector(".loading").classList.remove("loading"),!1})},p=(t,n)=>{console.log("start");let a={headers:{"Content-Type":"multipart/form-data"},onUploadProgress:function(e){let o=Math.round(e.loaded*100/e.total);$('[role="progressbar"]').css("width",o+"%")}};r.show(),c.post(t.action,n,a).then(function(e){console.log("yo?"),r.hide(),e.data.success}).catch(function(e){if(alert("oops"),r.hide(),e.response&&e.response.data.message){fileError.text(e.response.data.message).fadeToggle();let o=e.response.data.errors;Object.keys(o).forEach(s=>{window.showToast(o[s],"error")})}})}; diff --git a/public/build/manifest.json b/public/build/manifest.json index 78f428ea40..501ee74566 100644 --- a/public/build/manifest.json +++ b/public/build/manifest.json @@ -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" diff --git a/resources/js/campaigns/import.js b/resources/js/campaigns/import.js index da918c0205..554b14f0eb 100644 --- a/resources/js/campaigns/import.js +++ b/resources/js/campaigns/import.js @@ -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 = { @@ -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) { diff --git a/resources/views/campaigns/import/index.blade.php b/resources/views/campaigns/import/index.blade.php index 71e4b88816..8a9c5d8ebe 100644 --- a/resources/views/campaigns/import/index.blade.php +++ b/resources/views/campaigns/import/index.blade.php @@ -24,6 +24,7 @@ + @if ($token->isPrepared())