feat: add isAdmin parameter to interruzioneServizio and update related components
This commit is contained in:
parent
a11fc1241c
commit
aec6860cbd
3 changed files with 22 additions and 7 deletions
|
|
@ -135,7 +135,7 @@ export const DisclaimerInterruzioneServizio = () => {
|
||||||
<Confirm
|
<Confirm
|
||||||
description={t.servizio.interruzione.description}
|
description={t.servizio.interruzione.description}
|
||||||
onConfirm={() => {
|
onConfirm={() => {
|
||||||
interrompiServizio({ servizioId });
|
interrompiServizio({ servizioId, isAdmin: false });
|
||||||
}}
|
}}
|
||||||
title={t.servizio.interruzione.title}
|
title={t.servizio.interruzione.title}
|
||||||
>
|
>
|
||||||
|
|
@ -177,7 +177,16 @@ export const InterruzioneServizio = () => {
|
||||||
toast.success("Interruzione richiesta");
|
toast.success("Interruzione richiesta");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (!servizio.decorrenza) return null;
|
if (!servizio.decorrenza)
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
aria-label="Request Interruzione"
|
||||||
|
className="w-full"
|
||||||
|
disabled={true}
|
||||||
|
>
|
||||||
|
<ClockAlert /> <span>{t.servizio.interruzione.btn}</span>
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
const fineInterruzione = add(servizio.decorrenza, {
|
const fineInterruzione = add(servizio.decorrenza, {
|
||||||
days: servizio.interruzioneDays,
|
days: servizio.interruzioneDays,
|
||||||
});
|
});
|
||||||
|
|
@ -238,7 +247,9 @@ export const InterruzioneServizio = () => {
|
||||||
<AlertDialogCancel>{t.annulla}</AlertDialogCancel>
|
<AlertDialogCancel>{t.annulla}</AlertDialogCancel>
|
||||||
<AlertDialogAction
|
<AlertDialogAction
|
||||||
aria-label="Confirm Interruzione"
|
aria-label="Confirm Interruzione"
|
||||||
onClick={() => mutate({ servizioId: servizio.servizio_id })}
|
onClick={() =>
|
||||||
|
mutate({ servizioId: servizio.servizio_id, isAdmin })
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{t.conferma}
|
{t.conferma}
|
||||||
</AlertDialogAction>
|
</AlertDialogAction>
|
||||||
|
|
|
||||||
|
|
@ -244,10 +244,11 @@ export const servizioRouter = createTRPCRouter({
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
servizioId: zServizioId,
|
servizioId: zServizioId,
|
||||||
|
isAdmin: z.boolean(),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input }) => {
|
||||||
return await interruzioneServizio(input.servizioId);
|
return await interruzioneServizio(input.servizioId, input.isAdmin);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
processServizioOnboard: protectedProcedure
|
processServizioOnboard: protectedProcedure
|
||||||
|
|
|
||||||
|
|
@ -889,7 +889,10 @@ export const SbloccaContatti = async ({
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const interruzioneServizio = async (servizioId: ServizioServizioId) => {
|
export const interruzioneServizio = async (
|
||||||
|
servizioId: ServizioServizioId,
|
||||||
|
isAdmin: boolean,
|
||||||
|
) => {
|
||||||
try {
|
try {
|
||||||
const servizio = await getServizioById(servizioId);
|
const servizio = await getServizioById(servizioId);
|
||||||
|
|
||||||
|
|
@ -918,8 +921,8 @@ export const interruzioneServizio = async (servizioId: ServizioServizioId) => {
|
||||||
days: servizio.interruzioneDays,
|
days: servizio.interruzioneDays,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
//se non è admin deve essere entro il periodo di ripensamento per poter interrompere il servizio
|
||||||
if (!isWithinRipensamento) {
|
if (!isWithinRipensamento && !isAdmin) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
message: "Periodo di ripensamento scaduto",
|
message: "Periodo di ripensamento scaduto",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue