@@ -0,0 +1,97 @@
|
||||
import { router, useForm, usePage } from '@inertiajs/react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { FormErrors, controlClass } from '@/components/procurement';
|
||||
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
|
||||
|
||||
export function QuotationEvaluationForm({
|
||||
requisitionId,
|
||||
quotationId,
|
||||
}: {
|
||||
requisitionId: number;
|
||||
quotationId: number;
|
||||
}) {
|
||||
const actor = usePage().props.auth?.user;
|
||||
const historyKey = `quotation-evaluation:${actor?.tenant_id}:${actor?.id}:${requisitionId}:${quotationId}`;
|
||||
const initial = {
|
||||
quality: '5',
|
||||
history: '5',
|
||||
payment: '5',
|
||||
comment: '',
|
||||
no_conflict: false,
|
||||
};
|
||||
const evaluation = useForm(historyKey, initial);
|
||||
const ref = usePreparationDirty(evaluation.isDirty);
|
||||
return (
|
||||
<form
|
||||
ref={ref}
|
||||
className="mt-5 space-y-4 border-t pt-5"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
evaluation.post(`/cotacoes/${quotationId}/avaliar`, {
|
||||
onSuccess: () => {
|
||||
evaluation.reset();
|
||||
router.remember(initial, `${historyKey}:data`);
|
||||
router.remember({}, `${historyKey}:errors`);
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={evaluation.errors} />
|
||||
<div className="grid gap-4 md:grid-cols-3">
|
||||
{(
|
||||
[
|
||||
['quality', 'Qualidade técnica'],
|
||||
['history', 'Histórico (5 para novo)'],
|
||||
['payment', 'Condições de pagamento'],
|
||||
] as const
|
||||
).map(([key, label]) => (
|
||||
<div className="space-y-2" key={key}>
|
||||
<Label htmlFor={`evaluation-${quotationId}-${key}`}>
|
||||
{label} · 0 a 10
|
||||
</Label>
|
||||
<Input
|
||||
id={`evaluation-${quotationId}-${key}`}
|
||||
type="number"
|
||||
min="0"
|
||||
max="10"
|
||||
step="0.01"
|
||||
required
|
||||
value={evaluation.data[key]}
|
||||
onChange={(event) =>
|
||||
evaluation.setData(key, event.target.value)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<label className="grid gap-2 text-sm">
|
||||
Fundamento da avaliação
|
||||
<textarea
|
||||
className={`${controlClass} h-24 py-3`}
|
||||
required
|
||||
minLength={10}
|
||||
maxLength={2000}
|
||||
value={evaluation.data.comment}
|
||||
onChange={(event) =>
|
||||
evaluation.setData('comment', event.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<label className="flex items-start gap-2 text-sm">
|
||||
<input
|
||||
type="checkbox"
|
||||
required
|
||||
checked={evaluation.data.no_conflict}
|
||||
onChange={(event) =>
|
||||
evaluation.setData('no_conflict', event.target.checked)
|
||||
}
|
||||
/>
|
||||
Declaro não ter conflito de interesses e confirmo a minha
|
||||
avaliação independente.
|
||||
</label>
|
||||
<Button disabled={evaluation.processing}>Registar avaliação</Button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user