fix: show/enter service duration in hours instead of minutes in admin panel
Storage stays in minutes (duration_minutes); the admin form now takes hours (0.25 step) and the list shows the formatted "Xh Ym" duration.
This commit is contained in:
@@ -56,7 +56,7 @@ describe('AdminServices', () => {
|
||||
|
||||
await userEvent.type(screen.getByLabelText(/^id$/i), 'cornrows')
|
||||
await userEvent.type(screen.getByLabelText(/^nom$/i), 'Cornrows')
|
||||
await userEvent.type(screen.getByLabelText(/durée en minutes/i), '120')
|
||||
await userEvent.type(screen.getByLabelText(/durée en heures/i), '2')
|
||||
await userEvent.type(screen.getByLabelText(/prix à partir de/i), '90')
|
||||
await userEvent.type(screen.getByLabelText(/^description$/i), 'Classic style.')
|
||||
await userEvent.click(screen.getByRole('button', { name: /enregistrer le service/i }))
|
||||
|
||||
@@ -17,6 +17,12 @@ function emptyForm(): AdminService {
|
||||
return { id: '', name: '', duration_minutes: 0, price_from: 0, description: '', image: '' }
|
||||
}
|
||||
|
||||
function formatDuration(minutes: number): string {
|
||||
const hours = Math.floor(minutes / 60)
|
||||
const rest = minutes % 60
|
||||
return rest === 0 ? `${hours}h` : `${hours}h ${rest}m`
|
||||
}
|
||||
|
||||
function AdminServices() {
|
||||
const [servicesList, setServicesList] = useState<AdminService[]>([])
|
||||
const [form, setForm] = useState<AdminService>(emptyForm())
|
||||
@@ -91,7 +97,7 @@ function AdminServices() {
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nom</th>
|
||||
<th>Durée (min)</th>
|
||||
<th>Durée</th>
|
||||
<th>Prix à partir de</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
@@ -100,7 +106,7 @@ function AdminServices() {
|
||||
{servicesList.map((service) => (
|
||||
<tr key={service.id}>
|
||||
<td>{service.name}</td>
|
||||
<td>{service.duration_minutes}</td>
|
||||
<td>{formatDuration(service.duration_minutes)}</td>
|
||||
<td>{service.price_from} $</td>
|
||||
<td>
|
||||
<button type="button" className={styles.buttonSecondary} onClick={() => setForm(service)}>Modifier</button>
|
||||
@@ -133,12 +139,14 @@ function AdminServices() {
|
||||
/>
|
||||
</label>
|
||||
<label htmlFor="service-duration">
|
||||
Durée en minutes
|
||||
Durée en heures
|
||||
<input
|
||||
id="service-duration"
|
||||
type="number"
|
||||
value={form.duration_minutes}
|
||||
onChange={(e) => setForm((f) => ({ ...f, duration_minutes: Number(e.target.value) }))}
|
||||
step="0.25"
|
||||
min="0"
|
||||
value={form.duration_minutes / 60}
|
||||
onChange={(e) => setForm((f) => ({ ...f, duration_minutes: Math.round(Number(e.target.value) * 60) }))}
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
|
||||
Reference in New Issue
Block a user