You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.3 KiB
React

import React from 'react'
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'
const extractValue = (set, key) => {
const find = set.find((s) => s.key === key)
if (isEmpty(find) === false) {
if (find.type === 'image') {
return find?.url
}
return find?.value
}
return ''
}
export default function Setting(props) {
const { setting } = props
const { data, setData, post, processing, errors } = useForm({
app_name: extractValue(setting, 'app_name'),
})
const handleOnChange = (event) => {
setData(
event.target.name,
event.target.type === 'checkbox'
? event.target.checked
? 1
: 0
: event.target.value
)
}
const handleSubmit = () => {
post(route('setting.update'))
}
return (
<AuthenticatedLayout
auth={props.auth}
errors={props.errors}
flash={props.flash}
page={'Setting'}
action={''}
>
<Head title="Setting" />
<div>
<div className="mx-auto sm:px-6 lg:px-8">
<div className="overflow-hidden p-4 shadow-sm sm:rounded-lg bg-white dark:bg-gray-800 flex flex-col">
<div className="text-xl font-bold mb-4">Setting</div>
<FormInput
name="app_name"
value={data.app_name}
onChange={handleOnChange}
label="App Name"
error={errors.app_name}
/>
<div className="mt-2">
<Button
onClick={handleSubmit}
processing={processing}
>
Simpan
</Button>
</div>
</div>
</div>
</div>
</AuthenticatedLayout>
)
}