diff --git a/.gitignore b/.gitignore index 759ff42..b7a5ea4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /node_modules +/public/image /public/build /public/hot /public/storage diff --git a/app/Http/Controllers/GeneralController.php b/app/Http/Controllers/GeneralController.php index db3158e..ab9b114 100644 --- a/app/Http/Controllers/GeneralController.php +++ b/app/Http/Controllers/GeneralController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Storage; use Inertia\Inertia; class GeneralController extends Controller @@ -46,4 +47,16 @@ class GeneralController extends Controller { return Inertia::render('Gaji/UserGaji'); } + + public function uploadImage(Request $request) + { + $request->validate([ + 'profile' => 'required|image' + ]); + + $file = $request->file('profile'); + Storage::disk('public_pub')->put('image', $file); + + return response()->json(['file_name' => $file->hashName()]); + } } diff --git a/config/filesystems.php b/config/filesystems.php index e9d9dbd..0d91ae5 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -36,6 +36,14 @@ return [ 'throw' => false, ], + 'public_pub' => [ + 'driver' => 'local', + 'root' => base_path('public'), + 'url' => env('APP_URL'), + 'visibility' => 'public', + 'throw' => false, + ], + 'public' => [ 'driver' => 'local', 'root' => storage_path('app/public'), diff --git a/resources/js/Pages/Auth/Login.jsx b/resources/js/Pages/Auth/Login.jsx index 698667c..e57776b 100644 --- a/resources/js/Pages/Auth/Login.jsx +++ b/resources/js/Pages/Auth/Login.jsx @@ -30,6 +30,11 @@ export default function Login({ status, canResetPassword }) { username: user.username, password: user.password, is_admin: user.is_admin, + profile: user.profile, + jenisKelamin: user.jenisKelamin, + jabatan: user.jabatan.nama, + created_at: user.created_at, + status: user.status, id: user.id }) } else { @@ -63,6 +68,7 @@ export default function Login({ status, canResetPassword }) { jenisKelamin: "Laki-Laki", status: "Karyawan Tetap", is_admin: "true", + created_at: new Date() }) } }) diff --git a/resources/js/Pages/Dashboard.jsx b/resources/js/Pages/Dashboard.jsx index ca898e2..4620f2b 100644 --- a/resources/js/Pages/Dashboard.jsx +++ b/resources/js/Pages/Dashboard.jsx @@ -1,8 +1,14 @@ import React from 'react'; import Authenticated from '@/Layouts/Authenticated'; import { Head } from '@inertiajs/inertia-react'; +import { asset } from '@/Utils'; export default function Dashboard(props) { + const user = props.auth.user + + const created_at = new Date(user.created_at.seconds*1000) + const tglMasuk = `${created_at.getDate()}-${created_at.getMonth()}-${created_at.getFullYear()}` + return (
-
Hai, {props.auth.user.name}
+
Hai, {user.name}
+ {props.auth.user.name != 'admin' ? ( +
+
+

Data Pegawai

+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
Nama{user.name}
Jenis Kelamin{user.jenisKelamin}
Jabatan{user.jabatan}
Tanggal Masuk{tglMasuk}
Status{user.status}
+
+
+
+
+ ) : null} +
diff --git a/resources/js/Pages/Karyawan/FormModal.jsx b/resources/js/Pages/Karyawan/FormModal.jsx index 5f9ee98..72a854e 100644 --- a/resources/js/Pages/Karyawan/FormModal.jsx +++ b/resources/js/Pages/Karyawan/FormModal.jsx @@ -1,10 +1,10 @@ -import React, { useEffect, useState } from 'react' +import React, { useEffect, useState, useRef } from 'react' import { toast } from 'react-toastify' import { Modal } from '@/Components/Modal' import { useForm } from '@inertiajs/inertia-react' import Button from '@/Components/Button' import Input from '@/Components/Input' -import { create, update } from '@/Services/Karyawan' +import { create, update, uploadImage } from '@/Services/Karyawan' import { getAll as GetAllJabatan } from '@/Services/Jabatan' export default function FormModal({ modalState, refresh }) { @@ -17,9 +17,11 @@ export default function FormModal({ modalState, refresh }) { jenisKelamin: "Laki-Laki", jabatan: '', status: 'Karyawan Tetap', - is_admin: false + is_admin: false, + created_at: new Date() }) - + const [profile, setProfile] = useState(null) + const inputProfile = useRef() const [jabatans, setJabatans] = useState([]) useEffect(() => { @@ -29,11 +31,13 @@ export default function FormModal({ modalState, refresh }) { useEffect(() => { if (modalState.isOpen === false) { + setProfile(null) reset() modalState.setData(null) } if (modalState.data !== null) { setData(modalState.data.data) + setProfile(modalState.data.data.profile) } }, [modalState]) @@ -61,11 +65,12 @@ export default function FormModal({ modalState, refresh }) { }) } - const submit = (e) => { - e.preventDefault() - setLoading(true) + const UpdateOrSave = (image) => { if (modalState.data !== null) { - update(data, modalState.data.id) + update({ + ...data, + profile: image + }, modalState.data.id) .finally(() => { reset() toast.success("berhasil update") @@ -74,7 +79,10 @@ export default function FormModal({ modalState, refresh }) { refresh() }) } else { - create(data) + create({ + ...data, + profile: image + }) .then((id) => console.log(id)) .finally(() => { reset() @@ -86,6 +94,26 @@ export default function FormModal({ modalState, refresh }) { } } + const submit = (e) => { + e.preventDefault() + setLoading(true) + console.log(typeof(profile)) + if(typeof(profile) != "string") { + if (profile == null) { + alert('foto profile belum diisi') + return + } + uploadImage(route('upload.image'), profile) + .then(image => { + console.log(image.file_name) + UpdateOrSave(image.file_name) + }) + .catch((err) => console.log(err)) + } else { + UpdateOrSave(profile) + } + } + return (
Karyawan
@@ -194,6 +222,27 @@ export default function FormModal({ modalState, refresh }) { ))} +