Skip to content

Commit ae7232f

Browse files
Enhance Pulsa confirmation and upload views with edit handling and improved user feedback
1 parent 62dad34 commit ae7232f

File tree

4 files changed

+126
-24
lines changed

4 files changed

+126
-24
lines changed

app/Http/Controllers/PulsaController.php

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use App\Models\PulsaKegiatan;
99
use Illuminate\Http\Request;
1010
use SweetAlert2\Laravel\Swal;
11+
use Illuminate\Support\Facades\Storage;
1112

1213
class PulsaController extends Controller
1314
{
@@ -43,7 +44,7 @@ public function verifikasi(Request $request)
4344

4445
return redirect()->route('pulsa-actions', ['token' => $token]);
4546
} else {
46-
return redirect()->back()->withErrors(['NIK tidak terdaftar atau sudah diverifikasi.']);
47+
return redirect()->back()->withErrors(['NIK tidak terdaftar.']);
4748
}
4849
}
4950

@@ -96,9 +97,10 @@ public function confirm(Request $request)
9697
$matchKegiatan = PulsaKegiatan::where('id', session('pulsaKegiatanId'))
9798
->where('token', request()->route('token'))
9899
->exists();
99-
$matchMitra = DaftarPulsaMitra::where('mitra_id', session('mitraId'))
100+
$daftarMitra = DaftarPulsaMitra::where('mitra_id', session('mitraId'))
100101
->where('pulsa_kegiatan_id', session('pulsaKegiatanId'))
101-
->exists();
102+
->first();
103+
$matchMitra = ! is_null($daftarMitra);
102104
if (! $mitra || ! $matchKegiatan || ! $matchMitra) {
103105
abort(404);
104106
}
@@ -109,8 +111,11 @@ public function confirm(Request $request)
109111
$handphone = $mitra->no_pulsa;
110112
$version = Helper::version();
111113
$satker = 'BPS '.config('satker.kabupaten');
114+
$confirmed = optional($daftarMitra)->confirmed;
115+
$no_confirmed = optional($daftarMitra)->handphone;
116+
$edit = $request->input('edit');
112117

113-
return view('konfirmasi-pulsa', compact('judul', 'token', 'nik', 'nama', 'handphone', 'version', 'satker'));
118+
return view('konfirmasi-pulsa', compact('judul', 'token', 'nik', 'nama', 'handphone', 'version', 'satker', 'confirmed', 'no_confirmed', 'edit'));
114119
}
115120

116121
public function submitConfirm(Request $request)
@@ -125,11 +130,17 @@ public function submitConfirm(Request $request)
125130
if (! $mitra || ! $matchKegiatan || ! $matchMitra) {
126131
abort(404);
127132
}
133+
134+
if ($request->input('edit') === 'edit'){
135+
return redirect()->route('pulsa-confirm', [
136+
'token' => request()->route('token'),
137+
'edit' => $request->input('edit')
138+
]);
139+
}
128140
$request->validate([
129141
'handphone' => 'required|regex:/^\+?[0-9]{10,15}$/',
130142
'confirm' => 'required|same:handphone',
131143
]);
132-
133144
$token = request()->route('token');
134145
$handphone = $request->input('handphone');
135146
$mitraModel = Mitra::find(session('mitraId'));
@@ -171,14 +182,17 @@ public function upload(Request $request)
171182
$nama = $mitra->nama;
172183
$handphone = $mitra->no_pulsa;
173184
$nominal = DaftarPulsaMitra::getNominalByMitraIdAndKegiatanId(session('mitraId'), session('pulsaKegiatanId'));
174-
$uploaded = DaftarPulsaMitra::where('pulsa_kegiatan_id', session('pulsaKegiatanId'))
185+
$daftar = DaftarPulsaMitra::where('pulsa_kegiatan_id', session('pulsaKegiatanId'))
175186
->where('mitra_id', session('mitraId'))
176187
->whereNotNull('file')
177-
->exists();
188+
->first();
189+
$uploaded = !is_null($daftar);
190+
$path = $uploaded ? $daftar->file : null;
178191
$version = Helper::version();
179192
$satker = 'BPS '.config('satker.kabupaten');
193+
$edit = $request->input('edit');
180194

181-
return view('upload-pulsa', compact('judul', 'token', 'nik', 'nama', 'handphone', 'nominal', 'uploaded', 'version', 'satker'));
195+
return view('upload-pulsa', compact('judul', 'token', 'nik', 'nama', 'handphone', 'nominal', 'uploaded', 'version', 'satker', 'edit', 'path'));
182196
}
183197

184198
public function submitUpload(Request $request)
@@ -193,9 +207,23 @@ public function submitUpload(Request $request)
193207
if (! $mitra || ! $matchKegiatan || ! $matchMitra) {
194208
abort(404);
195209
}
210+
if ($request->input('edit') === 'edit'){
211+
return redirect()->route('pulsa-upload', [
212+
'token' => request()->route('token'),
213+
'edit' => $request->input('edit')
214+
]);
215+
}
196216
$request->validate([
197217
'attachment' => 'required|image|max:10240',
198218
]);
219+
// Remove previous file if exists
220+
$existing = DaftarPulsaMitra::where('pulsa_kegiatan_id', session('pulsaKegiatanId'))
221+
->where('mitra_id', session('mitraId'))
222+
->value('file');
223+
if ($existing) {
224+
Storage::disk('pulsa')->delete($existing);
225+
}
226+
// Store new file with new extension
199227
$attachment = $request->file('attachment')->storeAs(
200228
date('Y'),
201229
session('pulsaKegiatanId').'-'.session('mitraId').'.'.$request->file('attachment')->getClientOriginalExtension(),

resources/views/konfirmasi-pulsa.blade.php

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
<h2 class="form-title">Penggantian Pulsa {{ $judul }}</h2>
1111

1212
</div>
13+
14+
@if($confirmed && $edit !== 'edit')
15+
<div class="form-group">
16+
<p class="form-tips">
17+
SUDAH PERNAH KONFIRMASI
18+
</p>
19+
</div>
20+
@endif
1321

1422
<!-- Employee / Requester Information -->
1523
<div class="form-group">
@@ -36,6 +44,20 @@ class="form-input"
3644
value="{{ $nama }}"
3745
/>
3846
</div>
47+
@if($confirmed && $edit !== 'edit')
48+
<div class="form-group">
49+
<label for="handphone" class="form-label">Nomor Handphone*</label>
50+
<input
51+
type="text"
52+
name="handphone"
53+
id="handphone"
54+
class="form-input"
55+
readonly
56+
value="{{ $handphone }}"
57+
/>
58+
<input type="hidden" name="edit" value="edit" />
59+
</div>
60+
@else
3961
<div class="form-group">
4062
<p class="form-description">
4163
Isikan Nomor Handphone yang ingin diisikan pulsa. Perbaiki isian ini jika belum sesuai.
@@ -67,6 +89,7 @@ class="form-input"
6789
required
6890
/>
6991
</div>
92+
@endif
7093
@if ($errors->any())
7194
@foreach ($errors->all() as $error)
7295
<div class="form-group">
@@ -76,10 +99,20 @@ class="form-input"
7699
</div>
77100
@endforeach
78101
@endif
79-
102+
@if($confirmed && $edit !== 'edit')
103+
<div class="form-group">
104+
<button type="button" class="back-btn" onclick="window.location='{{ route('pulsa-actions', ['token' => $token]) }}'">KEMBALI</button>
105+
</div>
106+
@endif
80107
<!-- Submit Button -->
81-
<button type="submit" class="submit-btn"
82-
>Kirim</button
108+
<button type="submit" class="submit-btn">
109+
@if($confirmed && $edit !== 'edit')
110+
UBAH
111+
@else
112+
KIRIM
113+
@endif
114+
115+
</button
83116
>
84117
</form>
85118
@endsection

resources/views/pulsa/layout.blade.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,23 @@
5656
}
5757
5858
.form-description {
59+
background-color: #59c4eeff; /* bg-red-50 */
60+
padding: 10px;
61+
background-clip: padding-box;
62+
border: dotted darkblue;
63+
font-size: 15px;
64+
}
65+
66+
.form-warning {
5967
background-color: #f0c8c8ff; /* bg-red-50 */
6068
padding: 10px;
6169
background-clip: padding-box;
6270
border: dotted darkred;
6371
font-size: 15px;
6472
}
6573
66-
.form-tips {
74+
75+
.form-tips {
6776
background-color: #8df4a3ff; /* bg-red-50 */
6877
padding: 10px;
6978
background-clip: padding-box;
@@ -169,13 +178,34 @@
169178
transition: background-color 0.3s, box-shadow 0.3s;
170179
}
171180
181+
.back-btn {
182+
width: 100%;
183+
border-radius: 0.375rem; /* rounded-md */
184+
background-color: #d1351aff; /* bg-indigo-600 */
185+
padding: 0.75rem 1.5rem; /* px-6 py-3 */
186+
font-weight: 500; /* font-medium */
187+
color: white;
188+
border: none;
189+
cursor: pointer;
190+
transition: background-color 0.3s, box-shadow 0.3s;
191+
text-decoration:none;
192+
}
193+
172194
.submit-btn:hover {
173195
background-color: rgba(8, 136, 36, 0.5); /* hover:bg-indigo-700 */
174196
}
175197
176198
.submit-btn:focus {
177199
outline: none;
178200
box-shadow: 0 0 0 3px rgba(8, 136, 36, 0.5); /* focus:ring-2 focus:ring-indigo-500 focus:ring-opacity-50 */
201+
}
202+
.back-btn:hover {
203+
background-color: rgba(209, 53, 26, 0.5); /* hover:bg-indigo-700 */
204+
}
205+
206+
.back-btn:focus {
207+
outline: none;
208+
box-shadow: 0 0 0 3px rgba(209, 53, 26, 0.5); /* focus:ring-2 focus:ring-indigo-500 focus:ring-opacity-50 */
179209
}
180210
.footer {
181211
position: sticky;

resources/views/upload-pulsa.blade.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,12 @@
1010
<h2 class="form-title">Penggantian Pulsa {{ $judul }}</h2>
1111
</div>
1212

13-
@if($uploaded)
13+
@if($uploaded && $edit !== 'edit')
1414
<div class="form-group">
1515
<p class="form-tips">
1616
SUDAH PERNAH UPLOAD
1717
</p>
1818
</div>
19-
@else
20-
<div class="form-group">
21-
<p class="form-description">
22-
BELUM PERNAH UPLOAD.
23-
</p>
24-
</div>
2519
@endif
2620
<div class="form-group">
2721
<label for="nik" class="form-label">NIK*</label>
@@ -59,7 +53,7 @@ class="form-input"
5953
value="{{ $handphone }}"
6054
/>
6155
</div>
62-
<div class="form-group">
56+
<div class="form-group">
6357
<label for="nominal" class="form-label">Nominal*</label>
6458
<input
6559
type="text"
@@ -71,7 +65,11 @@ class="form-input"
7165
value="{{ $nominal }}"
7266
/>
7367
</div>
74-
<div class="form-group">
68+
@if($uploaded && $edit !== 'edit')
69+
<img class="form-image" src="{{ Storage::disk('pulsa')->url($path) }}" alt="Contoh Bukti Pulsa" class="example-image" />
70+
<input type="hidden" name="edit" value="edit" />
71+
@else
72+
<div class="form-group">
7573
<p class="form-tips">
7674
Contoh yang BENAR: <br/> Foto berfokus pada isi chat/SMS yang menunjukkan nominal yang jelas terlihat.
7775
</p>
@@ -84,7 +82,7 @@ class="form-input"
8482
<img class="form-image" src="{{ asset('images/collage.png') }}" alt="Contoh Bukti Pulsa" class="example-image" />
8583
</div>
8684
<div class="form-group">
87-
<p class="form-description">
85+
<p class="form-warning">
8886
Contoh yang SALAH: <br/> Screen capture layar penuh tidak berfokus pada isi chat/SMS pulsa masuk.
8987
</p>
9088
<img class="form-image" src="{{ asset('images/salah.png') }}" alt="Contoh Bukti Pulsa" class="example-image" />
@@ -102,6 +100,9 @@ class="form-input"
102100
required
103101
/>
104102
</div>
103+
@endif
104+
105+
105106
@if ($errors->any())
106107
@foreach ($errors->all() as $error)
107108
<div class="form-group">
@@ -111,9 +112,19 @@ class="form-input"
111112
</div>
112113
@endforeach
113114
@endif
115+
@if($uploaded && $edit !== 'edit')
116+
<div class="form-group">
117+
<button type="button" class="back-btn" onclick="window.location='{{ route('pulsa-actions', ['token' => $token]) }}'">KEMBALI</button>
118+
</div>
119+
@endif
114120
<!-- Submit Button -->
115121
<button type="submit" class="submit-btn"
116-
>Upload</button
117-
>
122+
>
123+
@if($uploaded && $edit !== 'edit')
124+
UBAH
125+
@else
126+
KIRIM
127+
@endif
128+
</button
118129
</form>
119130
@endsection

0 commit comments

Comments
 (0)