@@ -1,10 +1,13 @@
|
||||
import { useProcurementPreparationIdentity } from '@/hooks/use-procurement-preparation-identity';
|
||||
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
|
||||
import { hasPreparationChanges } from '@/lib/requisition-history';
|
||||
import { RequisitionApprovalSettings } from '@/components/requisition-approval-settings';
|
||||
import type { RequisitionApprovalPlan } from '@/components/requisition-approval-settings';
|
||||
import { CompanyDetailsSettings } from '@/components/company-details-settings';
|
||||
import type { CompanyDetails } from '@/components/company-details-settings';
|
||||
import { CompanyAdministrativeLocation } from '@/components/administrative-location';
|
||||
import type { GeographyDescription } from '@/components/administrative-location';
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import { Head, Link, router, useForm, useRemember } from '@inertiajs/react';
|
||||
import { AiPlanSettings } from '@/components/ai-plan-settings';
|
||||
import type { AiPlan } from '@/components/ai-plan-settings';
|
||||
import { IntelligenceSettings } from '@/components/intelligence-settings';
|
||||
@@ -86,20 +89,28 @@ function Assignment({
|
||||
version: number;
|
||||
}) {
|
||||
const assigned = members.filter((m) => m.user_id === person.id);
|
||||
const form = useForm({
|
||||
const identity = useProcurementPreparationIdentity(
|
||||
`company-assignment:${person.id}:${version}`,
|
||||
);
|
||||
const initial = {
|
||||
version,
|
||||
user_id: person.id,
|
||||
profile_ids: assigned.map((m) => m.profile_id),
|
||||
maintenance: assigned.some((m) => m.maintenance),
|
||||
expires_at: '',
|
||||
reason: '',
|
||||
});
|
||||
};
|
||||
const form = useForm(identity, initial);
|
||||
const dirty = hasPreparationChanges(initial, form.data);
|
||||
const ref = usePreparationDirty(dirty);
|
||||
return (
|
||||
<details className="rounded border p-4">
|
||||
<summary className="cursor-pointer font-medium">
|
||||
{person.name} · {person.email} · {assigned.length} perfil(is)
|
||||
</summary>
|
||||
<form
|
||||
ref={ref}
|
||||
data-preparation-dirty={dirty ? 'true' : 'false'}
|
||||
className="mt-4 space-y-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
@@ -110,8 +121,14 @@ function Assignment({
|
||||
: null,
|
||||
}));
|
||||
form.post(base + '/assign', {
|
||||
preserveState: 'errors',
|
||||
preserveState: true,
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
form.setData(initial);
|
||||
form.clearErrors();
|
||||
router.remember(initial, `${identity}:data`);
|
||||
router.remember({}, `${identity}:errors`);
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
@@ -171,7 +188,15 @@ function Assignment({
|
||||
</details>
|
||||
);
|
||||
}
|
||||
export default function Parameters({
|
||||
export default function Parameters(
|
||||
props: Omit<Parameters<typeof ParameterFields>[0], 'identity'>,
|
||||
) {
|
||||
const identity = useProcurementPreparationIdentity(
|
||||
`company-parameters:${props.version}:${props.active}:${props.ready}`,
|
||||
);
|
||||
return <ParameterFields key={identity} {...props} identity={identity} />;
|
||||
}
|
||||
function ParameterFields({
|
||||
approvalLevels,
|
||||
approvalLevelsReady = false,
|
||||
expiryReady = false,
|
||||
@@ -201,7 +226,9 @@ export default function Parameters({
|
||||
aiDataScopes = {},
|
||||
workContextConfiguration,
|
||||
enabledWorkContexts = [],
|
||||
identity,
|
||||
}: {
|
||||
identity: string;
|
||||
approvalLevels?: RequisitionApprovalPlan | null;
|
||||
approvalLevelsReady?: boolean;
|
||||
expiryReady?: boolean;
|
||||
@@ -238,14 +265,15 @@ export default function Parameters({
|
||||
default_tax_rate: string;
|
||||
};
|
||||
}) {
|
||||
const profile = useForm({
|
||||
version,
|
||||
id: '',
|
||||
name: '',
|
||||
permissions: [] as string[],
|
||||
work_contexts: [] as string[],
|
||||
});
|
||||
const user = useForm({
|
||||
const [selectedProfileId, setSelectedProfileId] = useRemember(
|
||||
'',
|
||||
`${identity}:selected-profile`,
|
||||
);
|
||||
const selectedProfile = profiles.find(
|
||||
(row) => String(row.id) === selectedProfileId,
|
||||
);
|
||||
const profileIdentity = `${identity}:profile:${selectedProfileId || 'new'}`;
|
||||
const initialUser = {
|
||||
version,
|
||||
name: '',
|
||||
email: '',
|
||||
@@ -254,29 +282,109 @@ export default function Parameters({
|
||||
department_id: '',
|
||||
profile_ids: [] as number[],
|
||||
reason: '',
|
||||
};
|
||||
const user = useForm(`${identity}:user`, initialUser).dontRemember(
|
||||
'password',
|
||||
'password_confirmation',
|
||||
);
|
||||
const userDirty = hasPreparationChanges(initialUser, {
|
||||
...initialUser,
|
||||
...user.data,
|
||||
});
|
||||
const activate = useForm({ version, confirm: false, reason: '' });
|
||||
const rules = useForm({
|
||||
const userRef = usePreparationDirty(userDirty);
|
||||
const clearUser = () => {
|
||||
user.setData(initialUser);
|
||||
user.clearErrors();
|
||||
const {
|
||||
password: _password,
|
||||
password_confirmation: _confirmation,
|
||||
...remembered
|
||||
} = initialUser;
|
||||
router.remember(remembered, `${identity}:user:data`);
|
||||
router.remember({}, `${identity}:user:errors`);
|
||||
};
|
||||
const initialActivate = { version, confirm: false, reason: '' };
|
||||
const activate = useForm(`${identity}:activate`, initialActivate);
|
||||
const activateDirty = hasPreparationChanges(initialActivate, activate.data);
|
||||
const activateRef = usePreparationDirty(activateDirty);
|
||||
const clearActivate = () => {
|
||||
activate.setData(initialActivate);
|
||||
activate.clearErrors();
|
||||
router.remember(initialActivate, `${identity}:activate:data`);
|
||||
router.remember({}, `${identity}:activate:errors`);
|
||||
};
|
||||
const initialRules = {
|
||||
version,
|
||||
first_limit: companyRules.first_limit,
|
||||
second_limit: companyRules.second_limit,
|
||||
includes_tax: companyRules.includes_tax,
|
||||
reason: '',
|
||||
});
|
||||
const department = useForm({ name: '' });
|
||||
const tax = useForm({
|
||||
};
|
||||
const rules = useForm(`${identity}:rules`, initialRules);
|
||||
const rulesDirty = hasPreparationChanges(initialRules, rules.data);
|
||||
const rulesRef = usePreparationDirty(rulesDirty);
|
||||
const clearRules = () => {
|
||||
rules.setData(initialRules);
|
||||
rules.clearErrors();
|
||||
router.remember(initialRules, `${identity}:rules:data`);
|
||||
router.remember({}, `${identity}:rules:errors`);
|
||||
};
|
||||
const initialDepartment = { name: '' };
|
||||
const department = useForm(`${identity}:department`, initialDepartment);
|
||||
const departmentDirty = hasPreparationChanges(
|
||||
initialDepartment,
|
||||
department.data,
|
||||
);
|
||||
const departmentRef = usePreparationDirty(departmentDirty);
|
||||
const clearDepartment = () => {
|
||||
department.setData(initialDepartment);
|
||||
department.clearErrors();
|
||||
router.remember(initialDepartment, `${identity}:department:data`);
|
||||
router.remember({}, `${identity}:department:errors`);
|
||||
};
|
||||
const initialTax = {
|
||||
version,
|
||||
default_tax_rate: companyRules.default_tax_rate,
|
||||
reason: '',
|
||||
});
|
||||
const center = useForm({ department_id: '', code: '', name: '' });
|
||||
const comparison = useForm({
|
||||
};
|
||||
const tax = useForm(`${identity}:tax`, initialTax);
|
||||
const taxDirty = hasPreparationChanges(initialTax, tax.data);
|
||||
const taxRef = usePreparationDirty(taxDirty);
|
||||
const clearTax = () => {
|
||||
tax.setData(initialTax);
|
||||
tax.clearErrors();
|
||||
router.remember(initialTax, `${identity}:tax:data`);
|
||||
router.remember({}, `${identity}:tax:errors`);
|
||||
};
|
||||
const initialCenter = { department_id: '', code: '', name: '' };
|
||||
const center = useForm(`${identity}:center`, initialCenter);
|
||||
const centerDirty = hasPreparationChanges(initialCenter, center.data);
|
||||
const centerRef = usePreparationDirty(centerDirty);
|
||||
const clearCenter = () => {
|
||||
center.setData(initialCenter);
|
||||
center.clearErrors();
|
||||
router.remember(initialCenter, `${identity}:center:data`);
|
||||
router.remember({}, `${identity}:center:errors`);
|
||||
};
|
||||
const initialComparison = {
|
||||
version,
|
||||
minimum_proposals: comparisonPolicy.minimum_proposals,
|
||||
minimum_evaluators: comparisonPolicy.minimum_evaluators,
|
||||
weights: { ...comparisonPolicy.weights },
|
||||
reason: '',
|
||||
});
|
||||
};
|
||||
const comparison = useForm(`${identity}:comparison`, initialComparison);
|
||||
const comparisonDirty = hasPreparationChanges(
|
||||
initialComparison,
|
||||
comparison.data,
|
||||
);
|
||||
const comparisonRef = usePreparationDirty(comparisonDirty);
|
||||
const clearComparison = () => {
|
||||
comparison.setData(initialComparison);
|
||||
comparison.clearErrors();
|
||||
router.remember(initialComparison, `${identity}:comparison:data`);
|
||||
router.remember({}, `${identity}:comparison:errors`);
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<Head title="Parametrização da aplicação" />
|
||||
@@ -364,12 +472,17 @@ export default function Parameters({
|
||||
</p>
|
||||
{!active && (
|
||||
<form
|
||||
ref={activateRef}
|
||||
data-preparation-dirty={
|
||||
activateDirty ? 'true' : 'false'
|
||||
}
|
||||
className="mt-4 space-y-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
activate.post(base + '/activate', {
|
||||
preserveState: 'errors',
|
||||
preserveState: true,
|
||||
preserveScroll: true,
|
||||
onSuccess: clearActivate,
|
||||
});
|
||||
}}
|
||||
>
|
||||
@@ -453,12 +566,17 @@ export default function Parameters({
|
||||
conflito de interesses.
|
||||
</p>
|
||||
<form
|
||||
ref={comparisonRef}
|
||||
data-preparation-dirty={
|
||||
comparisonDirty ? 'true' : 'false'
|
||||
}
|
||||
className="space-y-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
comparison.post(base + '/comparison', {
|
||||
preserveState: 'errors',
|
||||
preserveState: true,
|
||||
preserveScroll: true,
|
||||
onSuccess: clearComparison,
|
||||
});
|
||||
}}
|
||||
>
|
||||
@@ -588,12 +706,17 @@ export default function Parameters({
|
||||
descontos unitários incidem antes do IVA.
|
||||
</p>
|
||||
<form
|
||||
ref={taxRef}
|
||||
data-preparation-dirty={
|
||||
taxDirty ? 'true' : 'false'
|
||||
}
|
||||
className="space-y-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
tax.post(base + '/tax', {
|
||||
preserveState: 'errors',
|
||||
preserveState: true,
|
||||
preserveScroll: true,
|
||||
onSuccess: clearTax,
|
||||
});
|
||||
}}
|
||||
>
|
||||
@@ -647,12 +770,17 @@ export default function Parameters({
|
||||
anteriores.
|
||||
</p>
|
||||
<form
|
||||
ref={rulesRef}
|
||||
data-preparation-dirty={
|
||||
rulesDirty ? 'true' : 'false'
|
||||
}
|
||||
className="grid gap-4 sm:grid-cols-2"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
rules.post(base + '/rules', {
|
||||
preserveState: 'errors',
|
||||
preserveState: true,
|
||||
preserveScroll: true,
|
||||
onSuccess: clearRules,
|
||||
});
|
||||
}}
|
||||
>
|
||||
@@ -739,210 +867,38 @@ export default function Parameters({
|
||||
key={p.id}
|
||||
variant="outline"
|
||||
onClick={() =>
|
||||
profile.setData({
|
||||
version,
|
||||
id: String(p.id),
|
||||
name: p.name,
|
||||
permissions: p.permissions,
|
||||
work_contexts:
|
||||
p.work_contexts ?? [],
|
||||
})
|
||||
setSelectedProfileId(String(p.id))
|
||||
}
|
||||
>
|
||||
{p.name}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
<form
|
||||
className="space-y-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
profile.transform((values) => ({
|
||||
...values,
|
||||
id: values.id || null,
|
||||
}));
|
||||
profile.post(base + '/profile', {
|
||||
preserveState: 'errors',
|
||||
preserveScroll: true,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={profile.errors} />
|
||||
<label className="block space-y-1">
|
||||
Nome do perfil
|
||||
<input
|
||||
required
|
||||
maxLength={120}
|
||||
className={controlClass}
|
||||
value={profile.data.name}
|
||||
onChange={(e) =>
|
||||
profile.setData(
|
||||
'name',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
{workContextConfiguration && (
|
||||
<fieldset className="space-y-2">
|
||||
<legend className="font-medium">
|
||||
Contextos autorizados deste perfil
|
||||
</legend>
|
||||
<p className="text-sm">
|
||||
A associação não acrescenta
|
||||
permissões funcionais nem opções
|
||||
contratadas.
|
||||
</p>
|
||||
{Object.entries(
|
||||
workContextConfiguration.options,
|
||||
).map(([key, option]) => (
|
||||
<label
|
||||
className="flex items-center gap-2"
|
||||
key={key}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={profile.data.work_contexts.includes(
|
||||
key,
|
||||
)}
|
||||
onChange={(e) =>
|
||||
profile.setData(
|
||||
'work_contexts',
|
||||
e.target.checked
|
||||
? [
|
||||
...profile
|
||||
.data
|
||||
.work_contexts,
|
||||
key,
|
||||
]
|
||||
: profile.data.work_contexts.filter(
|
||||
(value) =>
|
||||
value !==
|
||||
key,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>
|
||||
{option.areaLabel} ·{' '}
|
||||
{option.label}
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
)}
|
||||
<fieldset className="grid gap-3 sm:grid-cols-2">
|
||||
<legend className="mb-2 font-medium">
|
||||
Tarefas e permissões do perfil
|
||||
</legend>
|
||||
{Object.entries(permissions).map(
|
||||
([key, label]) => (
|
||||
<label
|
||||
key={key}
|
||||
className="flex items-center gap-2 text-sm"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={profile.data.permissions.includes(
|
||||
key,
|
||||
)}
|
||||
onChange={(e) =>
|
||||
profile.setData(
|
||||
'permissions',
|
||||
e.target.checked
|
||||
? [
|
||||
...profile
|
||||
.data
|
||||
.permissions,
|
||||
key,
|
||||
]
|
||||
: profile.data.permissions.filter(
|
||||
(p) =>
|
||||
p !==
|
||||
key,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>
|
||||
<span>
|
||||
{label}
|
||||
<span className="mt-1 block text-xs text-muted-foreground">
|
||||
{(
|
||||
workflowTasks[
|
||||
key
|
||||
] ?? []
|
||||
).map((task) => (
|
||||
<span
|
||||
className="block"
|
||||
key={task.key}
|
||||
>
|
||||
{task.label}
|
||||
</span>
|
||||
))}
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
),
|
||||
)}
|
||||
</fieldset>
|
||||
<div className="rounded-md border p-4 text-sm">
|
||||
<p className="font-medium">
|
||||
Tarefas associadas a este perfil no
|
||||
workflow
|
||||
</p>
|
||||
<p className="mt-2 text-muted-foreground">
|
||||
Seleccione as tarefas nas permissões
|
||||
acima e atribua o perfil às pessoas. O
|
||||
contexto, departamento, equipa do
|
||||
processo, validade do acesso e
|
||||
independência continuam a limitar cada
|
||||
intervenção. Administração, por si só,
|
||||
não autoriza decisões de compras. Estas
|
||||
associações não alteram o percurso
|
||||
aprovado.
|
||||
</p>
|
||||
{profile.data.permissions.length === 0 ? (
|
||||
<p className="mt-3">
|
||||
Sem tarefas seleccionadas.
|
||||
</p>
|
||||
) : (
|
||||
<ul className="mt-3 list-disc space-y-1 pl-5">
|
||||
{profile.data.permissions
|
||||
.flatMap(
|
||||
(permission) =>
|
||||
workflowTasks[
|
||||
permission
|
||||
] ?? [],
|
||||
)
|
||||
.map((task) => (
|
||||
<li key={task.key}>
|
||||
{task.label}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
<ActionBar>
|
||||
<Button disabled={profile.processing}>
|
||||
{profile.data.id
|
||||
? 'Actualizar perfil'
|
||||
: 'Criar perfil'}
|
||||
</Button>
|
||||
{selectedProfileId && !selectedProfile ? (
|
||||
<p>
|
||||
Perfil seleccionado indisponível.{' '}
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() =>
|
||||
profile.setData({
|
||||
version,
|
||||
id: '',
|
||||
name: '',
|
||||
permissions: [],
|
||||
work_contexts: [],
|
||||
})
|
||||
}
|
||||
onClick={() => setSelectedProfileId('')}
|
||||
>
|
||||
Novo perfil
|
||||
</Button>
|
||||
</ActionBar>
|
||||
</form>
|
||||
</p>
|
||||
) : (
|
||||
<ProfileEditor
|
||||
key={profileIdentity}
|
||||
identity={profileIdentity}
|
||||
source={selectedProfile}
|
||||
version={version}
|
||||
permissions={permissions}
|
||||
workflowTasks={workflowTasks}
|
||||
workContextConfiguration={
|
||||
workContextConfiguration
|
||||
}
|
||||
onNew={() => setSelectedProfileId('')}
|
||||
/>
|
||||
)}
|
||||
</Panel>
|
||||
<Panel title="Utilizadores e atribuições">
|
||||
<div className="space-y-3">
|
||||
@@ -961,17 +917,17 @@ export default function Parameters({
|
||||
Criar utilizador
|
||||
</summary>
|
||||
<form
|
||||
ref={userRef}
|
||||
data-preparation-dirty={
|
||||
userDirty ? 'true' : 'false'
|
||||
}
|
||||
className="mt-4 grid gap-4 sm:grid-cols-2"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
user.post(base + '/user', {
|
||||
preserveState: 'errors',
|
||||
preserveState: true,
|
||||
preserveScroll: true,
|
||||
onSuccess: () =>
|
||||
user.reset(
|
||||
'password',
|
||||
'password_confirmation',
|
||||
),
|
||||
onSuccess: clearUser,
|
||||
});
|
||||
}}
|
||||
>
|
||||
@@ -1017,7 +973,7 @@ export default function Parameters({
|
||||
: undefined
|
||||
}
|
||||
className={controlClass}
|
||||
value={user.data[key]}
|
||||
value={user.data[key] ?? ''}
|
||||
onChange={(e) =>
|
||||
user.setData(
|
||||
key,
|
||||
@@ -1073,6 +1029,10 @@ export default function Parameters({
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<p className="text-sm text-muted-foreground sm:col-span-2">
|
||||
As palavras-passe não são conservadas ao
|
||||
sair deste ecrã.
|
||||
</p>
|
||||
<Button disabled={user.processing}>
|
||||
Criar utilizador
|
||||
</Button>
|
||||
@@ -1082,12 +1042,19 @@ export default function Parameters({
|
||||
<Panel title="Organização e centros de custo">
|
||||
<div className="grid gap-5 sm:grid-cols-2">
|
||||
<form
|
||||
ref={departmentRef}
|
||||
data-preparation-dirty={
|
||||
departmentDirty ? 'true' : 'false'
|
||||
}
|
||||
className="space-y-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
department.post(
|
||||
'/empresa/departamentos',
|
||||
{ preserveScroll: true },
|
||||
{
|
||||
preserveScroll: true,
|
||||
onSuccess: clearDepartment,
|
||||
},
|
||||
);
|
||||
}}
|
||||
>
|
||||
@@ -1116,12 +1083,19 @@ export default function Parameters({
|
||||
</p>
|
||||
</form>
|
||||
<form
|
||||
ref={centerRef}
|
||||
data-preparation-dirty={
|
||||
centerDirty ? 'true' : 'false'
|
||||
}
|
||||
className="space-y-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
center.post(
|
||||
'/empresa/centros-de-custo',
|
||||
{ preserveScroll: true },
|
||||
{
|
||||
preserveScroll: true,
|
||||
onSuccess: clearCenter,
|
||||
},
|
||||
);
|
||||
}}
|
||||
>
|
||||
@@ -1204,3 +1178,181 @@ export default function Parameters({
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function ProfileEditor({
|
||||
identity,
|
||||
source,
|
||||
version,
|
||||
permissions,
|
||||
workflowTasks = {},
|
||||
workContextConfiguration,
|
||||
onNew,
|
||||
}: {
|
||||
identity: string;
|
||||
source?: Profile;
|
||||
version: number;
|
||||
permissions: { [key: string]: string };
|
||||
workflowTasks?: Record<string, { key: string; label: string }[]>;
|
||||
workContextConfiguration?: WorkContextState;
|
||||
onNew: () => void;
|
||||
}) {
|
||||
const initialProfile = {
|
||||
version,
|
||||
id: source ? String(source.id) : '',
|
||||
name: source?.name ?? '',
|
||||
permissions: [...(source?.permissions ?? [])],
|
||||
work_contexts: [...(source?.work_contexts ?? [])],
|
||||
};
|
||||
const profile = useForm(identity, initialProfile);
|
||||
const profileDirty = hasPreparationChanges(initialProfile, profile.data);
|
||||
const profileRef = usePreparationDirty(profileDirty);
|
||||
const clearProfile = () => {
|
||||
profile.setData(initialProfile);
|
||||
profile.clearErrors();
|
||||
router.remember(initialProfile, `${identity}:data`);
|
||||
router.remember({}, `${identity}:errors`);
|
||||
onNew();
|
||||
};
|
||||
return (
|
||||
<form
|
||||
ref={profileRef}
|
||||
data-preparation-dirty={profileDirty ? 'true' : 'false'}
|
||||
className="space-y-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
profile.transform((values) => ({
|
||||
...values,
|
||||
id: values.id || null,
|
||||
}));
|
||||
profile.post(base + '/profile', {
|
||||
preserveState: true,
|
||||
preserveScroll: true,
|
||||
onSuccess: clearProfile,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={profile.errors} />
|
||||
<label className="block space-y-1">
|
||||
Nome do perfil
|
||||
<input
|
||||
required
|
||||
maxLength={120}
|
||||
className={controlClass}
|
||||
value={profile.data.name}
|
||||
onChange={(e) => profile.setData('name', e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
{workContextConfiguration && (
|
||||
<fieldset className="space-y-2">
|
||||
<legend className="font-medium">
|
||||
Contextos autorizados deste perfil
|
||||
</legend>
|
||||
<p className="text-sm">
|
||||
A associação não acrescenta permissões funcionais nem
|
||||
opções contratadas.
|
||||
</p>
|
||||
{Object.entries(workContextConfiguration.options).map(
|
||||
([key, option]) => (
|
||||
<label
|
||||
className="flex items-center gap-2"
|
||||
key={key}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={profile.data.work_contexts.includes(
|
||||
key,
|
||||
)}
|
||||
onChange={(e) =>
|
||||
profile.setData(
|
||||
'work_contexts',
|
||||
e.target.checked
|
||||
? [
|
||||
...profile.data
|
||||
.work_contexts,
|
||||
key,
|
||||
]
|
||||
: profile.data.work_contexts.filter(
|
||||
(value) => value !== key,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>
|
||||
{option.areaLabel} · {option.label}
|
||||
</label>
|
||||
),
|
||||
)}
|
||||
</fieldset>
|
||||
)}
|
||||
<fieldset className="grid gap-3 sm:grid-cols-2">
|
||||
<legend className="mb-2 font-medium">
|
||||
Tarefas e permissões do perfil
|
||||
</legend>
|
||||
{Object.entries(permissions).map(([key, label]) => (
|
||||
<label
|
||||
key={key}
|
||||
className="flex items-center gap-2 text-sm"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={profile.data.permissions.includes(key)}
|
||||
onChange={(e) =>
|
||||
profile.setData(
|
||||
'permissions',
|
||||
e.target.checked
|
||||
? [...profile.data.permissions, key]
|
||||
: profile.data.permissions.filter(
|
||||
(p) => p !== key,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>
|
||||
<span>
|
||||
{label}
|
||||
<span className="mt-1 block text-xs text-muted-foreground">
|
||||
{(workflowTasks[key] ?? []).map((task) => (
|
||||
<span className="block" key={task.key}>
|
||||
{task.label}
|
||||
</span>
|
||||
))}
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
<div className="rounded-md border p-4 text-sm">
|
||||
<p className="font-medium">
|
||||
Tarefas associadas a este perfil no workflow
|
||||
</p>
|
||||
<p className="mt-2 text-muted-foreground">
|
||||
Seleccione as tarefas nas permissões acima e atribua o
|
||||
perfil às pessoas. O contexto, departamento, equipa do
|
||||
processo, validade do acesso e independência continuam a
|
||||
limitar cada intervenção. Administração, por si só, não
|
||||
autoriza decisões de compras. Estas associações não alteram
|
||||
o percurso aprovado.
|
||||
</p>
|
||||
{profile.data.permissions.length === 0 ? (
|
||||
<p className="mt-3">Sem tarefas seleccionadas.</p>
|
||||
) : (
|
||||
<ul className="mt-3 list-disc space-y-1 pl-5">
|
||||
{profile.data.permissions
|
||||
.flatMap(
|
||||
(permission) => workflowTasks[permission] ?? [],
|
||||
)
|
||||
.map((task) => (
|
||||
<li key={task.key}>{task.label}</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
<ActionBar>
|
||||
<Button disabled={profile.processing}>
|
||||
{profile.data.id ? 'Actualizar perfil' : 'Criar perfil'}
|
||||
</Button>
|
||||
<Button type="button" variant="outline" onClick={() => onNew()}>
|
||||
Novo perfil
|
||||
</Button>
|
||||
</ActionBar>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user