Correcao Sidebar Classico e Rail, Correcao Layout, Ajuste de Breakpoint para Tailwind, Ajuste AppTopbar, Ajuste Menu PopOver, Recriado Paleta de Cores, Inserido algumas animações leves, Reajuste Cor items NOVOS da tabela, Drawer Ajuda Corrigido no Logout, Whatsapp, sms, email, recursos extras
This commit is contained in:
@@ -27,175 +27,166 @@
|
||||
// togglePlanService(id, active) – alterna active do procedimento
|
||||
// removePlanService(id) – DELETE definitivo do procedimento
|
||||
|
||||
import { ref } from 'vue'
|
||||
import { supabase } from '@/lib/supabase/client'
|
||||
import { ref } from 'vue';
|
||||
import { supabase } from '@/lib/supabase/client';
|
||||
|
||||
export function useInsurancePlans () {
|
||||
const plans = ref([])
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
export function useInsurancePlans() {
|
||||
const plans = ref([]);
|
||||
const loading = ref(false);
|
||||
const error = ref(null);
|
||||
|
||||
async function load (ownerId) {
|
||||
if (!ownerId) return
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const { data, error: err } = await supabase
|
||||
.from('insurance_plans')
|
||||
.select(`
|
||||
async function load(ownerId) {
|
||||
if (!ownerId) return;
|
||||
loading.value = true;
|
||||
error.value = null;
|
||||
try {
|
||||
const { data, error: err } = await supabase
|
||||
.from('insurance_plans')
|
||||
.select(
|
||||
`
|
||||
*,
|
||||
insurance_plan_services (
|
||||
id, name, value, active
|
||||
)
|
||||
`)
|
||||
.eq('owner_id', ownerId)
|
||||
.order('name')
|
||||
if (err) throw err
|
||||
plans.value = data || []
|
||||
} catch (e) {
|
||||
error.value = e?.message || 'Erro ao carregar convênios'
|
||||
plans.value = []
|
||||
} finally {
|
||||
loading.value = false
|
||||
`
|
||||
)
|
||||
.eq('owner_id', ownerId)
|
||||
.order('name');
|
||||
if (err) throw err;
|
||||
plans.value = data || [];
|
||||
} catch (e) {
|
||||
error.value = e?.message || 'Erro ao carregar convênios';
|
||||
plans.value = [];
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function save (payload) {
|
||||
error.value = null
|
||||
try {
|
||||
if (payload.id) {
|
||||
const { error: err } = await supabase
|
||||
.from('insurance_plans')
|
||||
.update({
|
||||
name: payload.name,
|
||||
notes: payload.notes || null,
|
||||
updated_at: new Date().toISOString(),
|
||||
})
|
||||
.eq('id', payload.id)
|
||||
if (err) throw err
|
||||
} else {
|
||||
const { error: err } = await supabase
|
||||
.from('insurance_plans')
|
||||
.insert({
|
||||
owner_id: payload.owner_id,
|
||||
tenant_id: payload.tenant_id,
|
||||
name: payload.name,
|
||||
notes: payload.notes || null,
|
||||
})
|
||||
if (err) throw err
|
||||
}
|
||||
} catch (e) {
|
||||
error.value = e?.message || 'Erro ao salvar convênio'
|
||||
throw e
|
||||
async function save(payload) {
|
||||
error.value = null;
|
||||
try {
|
||||
if (payload.id) {
|
||||
const { error: err } = await supabase
|
||||
.from('insurance_plans')
|
||||
.update({
|
||||
name: payload.name,
|
||||
notes: payload.notes || null,
|
||||
updated_at: new Date().toISOString()
|
||||
})
|
||||
.eq('id', payload.id);
|
||||
if (err) throw err;
|
||||
} else {
|
||||
const { error: err } = await supabase.from('insurance_plans').insert({
|
||||
owner_id: payload.owner_id,
|
||||
tenant_id: payload.tenant_id,
|
||||
name: payload.name,
|
||||
notes: payload.notes || null
|
||||
});
|
||||
if (err) throw err;
|
||||
}
|
||||
} catch (e) {
|
||||
error.value = e?.message || 'Erro ao salvar convênio';
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function toggle (id, active) {
|
||||
error.value = null
|
||||
try {
|
||||
const { error: err } = await supabase
|
||||
.from('insurance_plans')
|
||||
.update({ active })
|
||||
.eq('id', id)
|
||||
if (err) throw err
|
||||
const plan = plans.value.find(p => p.id === id)
|
||||
if (plan) plan.active = active
|
||||
} catch (e) {
|
||||
error.value = e?.message || 'Erro ao atualizar convênio'
|
||||
throw e
|
||||
async function toggle(id, active) {
|
||||
error.value = null;
|
||||
try {
|
||||
const { error: err } = await supabase.from('insurance_plans').update({ active }).eq('id', id);
|
||||
if (err) throw err;
|
||||
const plan = plans.value.find((p) => p.id === id);
|
||||
if (plan) plan.active = active;
|
||||
} catch (e) {
|
||||
error.value = e?.message || 'Erro ao atualizar convênio';
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function remove (id) {
|
||||
error.value = null
|
||||
try {
|
||||
const { error: err } = await supabase
|
||||
.from('insurance_plans')
|
||||
.update({ active: false })
|
||||
.eq('id', id)
|
||||
if (err) throw err
|
||||
const plan = plans.value.find(p => p.id === id)
|
||||
if (plan) plan.active = false
|
||||
} catch (e) {
|
||||
error.value = e?.message || 'Erro ao remover convênio'
|
||||
throw e
|
||||
async function remove(id) {
|
||||
error.value = null;
|
||||
try {
|
||||
const { error: err } = await supabase.from('insurance_plans').update({ active: false }).eq('id', id);
|
||||
if (err) throw err;
|
||||
const plan = plans.value.find((p) => p.id === id);
|
||||
if (plan) plan.active = false;
|
||||
} catch (e) {
|
||||
error.value = e?.message || 'Erro ao remover convênio';
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function savePlanService (payload) {
|
||||
error.value = null
|
||||
try {
|
||||
if (payload.id) {
|
||||
const { error: err } = await supabase
|
||||
.from('insurance_plan_services')
|
||||
.update({
|
||||
name: payload.name,
|
||||
value: payload.value,
|
||||
})
|
||||
.eq('id', payload.id)
|
||||
if (err) throw err
|
||||
} else {
|
||||
const { error: err } = await supabase
|
||||
.from('insurance_plan_services')
|
||||
.insert({
|
||||
insurance_plan_id: payload.insurance_plan_id,
|
||||
name: payload.name,
|
||||
value: payload.value,
|
||||
})
|
||||
if (err) throw err
|
||||
}
|
||||
} catch (e) {
|
||||
error.value = e?.message || 'Erro ao salvar procedimento'
|
||||
throw e
|
||||
async function savePlanService(payload) {
|
||||
error.value = null;
|
||||
try {
|
||||
if (payload.id) {
|
||||
const { error: err } = await supabase
|
||||
.from('insurance_plan_services')
|
||||
.update({
|
||||
name: payload.name,
|
||||
value: payload.value
|
||||
})
|
||||
.eq('id', payload.id);
|
||||
if (err) throw err;
|
||||
} else {
|
||||
const { error: err } = await supabase.from('insurance_plan_services').insert({
|
||||
insurance_plan_id: payload.insurance_plan_id,
|
||||
name: payload.name,
|
||||
value: payload.value
|
||||
});
|
||||
if (err) throw err;
|
||||
}
|
||||
} catch (e) {
|
||||
error.value = e?.message || 'Erro ao salvar procedimento';
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function togglePlanService (id, active) {
|
||||
error.value = null
|
||||
try {
|
||||
const { error: err } = await supabase
|
||||
.from('insurance_plan_services')
|
||||
.update({ active })
|
||||
.eq('id', id)
|
||||
if (err) throw err
|
||||
} catch (e) {
|
||||
error.value = e?.message || 'Erro ao atualizar procedimento'
|
||||
throw e
|
||||
async function togglePlanService(id, active) {
|
||||
error.value = null;
|
||||
try {
|
||||
const { error: err } = await supabase.from('insurance_plan_services').update({ active }).eq('id', id);
|
||||
if (err) throw err;
|
||||
} catch (e) {
|
||||
error.value = e?.message || 'Erro ao atualizar procedimento';
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function removeDefinitivo (id) {
|
||||
error.value = null
|
||||
try {
|
||||
const { error: err } = await supabase
|
||||
.from('insurance_plans')
|
||||
.delete()
|
||||
.eq('id', id)
|
||||
if (err) throw err
|
||||
plans.value = plans.value.filter(p => p.id !== id)
|
||||
} catch (e) {
|
||||
error.value = e?.message || 'Erro ao remover convênio'
|
||||
throw e
|
||||
async function removeDefinitivo(id) {
|
||||
error.value = null;
|
||||
try {
|
||||
const { error: err } = await supabase.from('insurance_plans').delete().eq('id', id);
|
||||
if (err) throw err;
|
||||
plans.value = plans.value.filter((p) => p.id !== id);
|
||||
} catch (e) {
|
||||
error.value = e?.message || 'Erro ao remover convênio';
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function removePlanService (id) {
|
||||
error.value = null
|
||||
try {
|
||||
const { error: err } = await supabase
|
||||
.from('insurance_plan_services')
|
||||
.delete()
|
||||
.eq('id', id)
|
||||
if (err) throw err
|
||||
} catch (e) {
|
||||
error.value = e?.message || 'Erro ao remover procedimento'
|
||||
throw e
|
||||
async function removePlanService(id) {
|
||||
error.value = null;
|
||||
try {
|
||||
const { error: err } = await supabase.from('insurance_plan_services').delete().eq('id', id);
|
||||
if (err) throw err;
|
||||
} catch (e) {
|
||||
error.value = e?.message || 'Erro ao remover procedimento';
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
plans, loading, error,
|
||||
load, save, toggle, remove, removeDefinitivo,
|
||||
savePlanService, togglePlanService, removePlanService,
|
||||
}
|
||||
return {
|
||||
plans,
|
||||
loading,
|
||||
error,
|
||||
load,
|
||||
save,
|
||||
toggle,
|
||||
remove,
|
||||
removeDefinitivo,
|
||||
savePlanService,
|
||||
togglePlanService,
|
||||
removePlanService
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user