add reset button

dev
Aji Kamaludin 10 months ago
parent 5f1c4d809e
commit f2307117ca
No known key found for this signature in database
GPG Key ID: 19058F67F0083AD3

@ -3,6 +3,8 @@
namespace App\Http\Controllers;
use App\Models\Customer;
use App\Models\CustomerPoint;
use Illuminate\Support\Facades\DB;
class GeneralController extends Controller
{
@ -17,4 +19,16 @@ class GeneralController extends Controller
{
return inertia('Maintance');
}
public function reset()
{
DB::beginTransaction();
CustomerPoint::truncate();
Customer::truncate();
DB::commit();
return redirect()->route('setting.index')
->with('message', ['type' => 'success', 'message' => 'All data has been reset']);
}
}

@ -1,31 +1,29 @@
import { Spinner } from "flowbite-react";
import React from "react";
import { Spinner } from 'flowbite-react'
import React from 'react'
export default function Button({ children, type = "", processing, onClick }) {
let className = ""
if(type === "" || type === "primary") {
className = "text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 mr-2 mb-2 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800"
} else if (type === "secondary") {
className = "text-gray-900 bg-white border border-gray-300 focus:outline-none hover:bg-gray-100 focus:ring-4 focus:ring-gray-200 font-medium rounded-lg text-sm px-5 py-2.5 mr-2 mb-2 dark:bg-gray-800 dark:text-white dark:border-gray-600 dark:hover:bg-gray-700 dark:hover:border-gray-600 dark:focus:ring-gray-700"
export default function Button({ children, type = '', processing, onClick }) {
let className = ''
if (type === '' || type === 'primary') {
className =
'text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 mr-2 mb-2 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800'
} else if (type === 'secondary') {
className =
'text-gray-900 bg-white border border-gray-300 focus:outline-none hover:bg-gray-100 focus:ring-4 focus:ring-gray-200 font-medium rounded-lg text-sm px-5 py-2.5 mr-2 mb-2 dark:bg-gray-800 dark:text-white dark:border-gray-600 dark:hover:bg-gray-700 dark:hover:border-gray-600 dark:focus:ring-gray-700'
} else if (type === 'danger') {
className =
'focus:outline-none text-white bg-red-700 hover:bg-red-800 focus:ring-4 focus:ring-red-300 font-medium rounded-lg text-sm px-5 py-2.5 mr-2 mb-2 dark:bg-red-600 dark:hover:bg-red-700 dark:focus:ring-red-900'
}
return (
<button
type="button"
<button
type="button"
className={className}
disabled={processing}
onClick={onClick}
>
<div className="flex items-center justify-between space-x-1">
{processing ? (
<Spinner/>
) : (
<div>
{children}
</div>
)}
{processing ? <Spinner /> : <div>{children}</div>}
</div>
</button>
)
}
}

@ -1,10 +1,12 @@
import React from 'react'
import { Head, useForm, router } from '@inertiajs/react'
import { isEmpty } from 'lodash'
import { useModalState } from '@/hooks'
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'
import FormInput from '@/Components/FormInput'
import Button from '@/Components/Button'
import { Head, useForm } from '@inertiajs/react'
import TextArea from '@/Components/TextArea'
import { isEmpty } from 'lodash'
import ModalConfirm from '@/Components/ModalConfirm'
const extractValue = (set, key) => {
const find = set.find((s) => s.key === key)
@ -39,6 +41,12 @@ export default function Setting(props) {
post(route('setting.update'))
}
const confirmModal = useModalState()
const onReset = () => {
router.post(route('setting.reset'))
}
return (
<AuthenticatedLayout
auth={props.auth}
@ -68,6 +76,23 @@ export default function Setting(props) {
Simpan
</Button>
</div>
<div className="mt-5 border rounded-md p-4 flex flex-col">
<label className="font-bold mb-2">
Reset All Data
</label>
<div>
<Button
type="danger"
onClick={confirmModal.toggle}
>
Reset
</Button>
</div>
<ModalConfirm
modalState={confirmModal}
onConfirm={onReset}
/>
</div>
</div>
</div>
</div>

@ -40,6 +40,7 @@ Route::middleware(['auth'])->group(function () {
// Setting
Route::get('/setting', [SettingController::class, 'index'])->name('setting.index');
Route::post('/setting', [SettingController::class, 'update'])->name('setting.update');
Route::post('/setting/reset', [GeneralController::class, 'reset'])->name('setting.reset');
// Customer
Route::get('/customers', [CustomerController::class, 'index'])->name('customer.index');

Loading…
Cancel
Save