feat(web): switch ativar/desativar em promocoes e regras de desconto
Coluna "Ativa" com switch nas tabelas das duas abas (liga/desliga na hora, sem abrir o modal) e campo Ativa no modal de edicao. Desativada, a promocao/regra sai imediatamente do catalogo e da alcada. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
Select,
|
||||
Skeleton,
|
||||
Space,
|
||||
Switch,
|
||||
Table,
|
||||
Tabs,
|
||||
Tag,
|
||||
@@ -232,6 +233,7 @@ interface PromocaoForm {
|
||||
grpProd?: string;
|
||||
descPct: number;
|
||||
periodo: [dayjs.Dayjs, dayjs.Dayjs];
|
||||
ativa?: boolean;
|
||||
}
|
||||
|
||||
function TabPromocoes() {
|
||||
@@ -271,10 +273,20 @@ function TabPromocoes() {
|
||||
grpProd: p.grpProd ?? undefined,
|
||||
descPct: p.descPct,
|
||||
periodo: [dayjs(p.dataInicio), dayjs(p.dataFim)],
|
||||
ativa: p.ativa,
|
||||
});
|
||||
setModalOpen(true);
|
||||
}
|
||||
|
||||
async function toggleAtiva(p: Promocao, ativa: boolean) {
|
||||
try {
|
||||
await updateMutation.mutateAsync({ id: p.id, body: { ativa } });
|
||||
} catch {
|
||||
return; // erro já notificado pelo handler global do QueryClient
|
||||
}
|
||||
void msg.success(ativa ? 'Promocao ativada' : 'Promocao desativada');
|
||||
}
|
||||
|
||||
async function handleSubmit(values: PromocaoForm) {
|
||||
const [inicio, fim] = values.periodo;
|
||||
try {
|
||||
@@ -288,6 +300,7 @@ function TabPromocoes() {
|
||||
descPct: values.descPct,
|
||||
dataInicio: inicio.format('YYYY-MM-DD'),
|
||||
dataFim: fim.format('YYYY-MM-DD'),
|
||||
ativa: values.ativa ?? true,
|
||||
},
|
||||
});
|
||||
void msg.success('Promocao atualizada');
|
||||
@@ -362,6 +375,19 @@ function TabPromocoes() {
|
||||
return <Tag color="green">Ativa</Tag>;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Ativa',
|
||||
width: 70,
|
||||
align: 'center' as const,
|
||||
render: (_: unknown, row: Promocao) => (
|
||||
<Switch
|
||||
size="small"
|
||||
checked={row.ativa}
|
||||
loading={updateMutation.isPending}
|
||||
onChange={(checked) => void toggleAtiva(row, checked)}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '',
|
||||
width: 100,
|
||||
@@ -446,6 +472,9 @@ function TabPromocoes() {
|
||||
optionFilterProp="label"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="ativa" label="Ativa" valuePropName="checked">
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
</Flex>
|
||||
) : (
|
||||
<>
|
||||
@@ -509,6 +538,7 @@ interface RegraForm {
|
||||
codSubgrupo?: number;
|
||||
descPct: number;
|
||||
periodo: [dayjs.Dayjs, dayjs.Dayjs];
|
||||
ativa?: boolean;
|
||||
}
|
||||
|
||||
function TabRegras() {
|
||||
@@ -575,10 +605,20 @@ function TabRegras() {
|
||||
codSubgrupo: r.codSubgrupo ?? undefined,
|
||||
descPct: r.descPct,
|
||||
periodo: [dayjs(r.dataInicio), dayjs(r.dataFim)],
|
||||
ativa: r.ativa,
|
||||
});
|
||||
setModalOpen(true);
|
||||
}
|
||||
|
||||
async function toggleAtiva(r: RegraDesconto, ativa: boolean) {
|
||||
try {
|
||||
await updateMutation.mutateAsync({ id: r.id, body: { ativa } });
|
||||
} catch {
|
||||
return; // erro já notificado pelo handler global do QueryClient
|
||||
}
|
||||
void msg.success(ativa ? 'Regra ativada' : 'Regra desativada');
|
||||
}
|
||||
|
||||
async function handleSubmit(values: RegraForm) {
|
||||
const [inicio, fim] = values.periodo;
|
||||
try {
|
||||
@@ -593,6 +633,7 @@ function TabRegras() {
|
||||
descPct: values.descPct,
|
||||
dataInicio: inicio.format('YYYY-MM-DD'),
|
||||
dataFim: fim.format('YYYY-MM-DD'),
|
||||
ativa: values.ativa ?? true,
|
||||
},
|
||||
});
|
||||
void msg.success('Regra atualizada');
|
||||
@@ -678,6 +719,19 @@ function TabRegras() {
|
||||
return <Tag color="green">Ativa</Tag>;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Ativa',
|
||||
width: 70,
|
||||
align: 'center' as const,
|
||||
render: (_: unknown, row: RegraDesconto) => (
|
||||
<Switch
|
||||
size="small"
|
||||
checked={row.ativa}
|
||||
loading={updateMutation.isPending}
|
||||
onChange={(checked) => void toggleAtiva(row, checked)}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '',
|
||||
width: 100,
|
||||
@@ -783,6 +837,9 @@ function TabRegras() {
|
||||
optionFilterProp="label"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="ativa" label="Ativa" valuePropName="checked">
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
</Flex>
|
||||
) : (
|
||||
<>
|
||||
|
||||
Reference in New Issue
Block a user