Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve o side effect na store de etapas que quebrava os campos do form #138

Open
wants to merge 1 commit into
base: homol
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions frontend/src/stores/etapas.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,17 @@ export const useEtapasStore = defineStore({
}
return null;
},
// mantendo comportamento legado
// eslint-disable-next-line consistent-return
async getAll(cronograma_id) {
try {
if (!this.Etapas[cronograma_id]) {
this.Etapas[cronograma_id] = { loading: true };
const r = await this.requestS.get(`${baseUrl}/${caminhoParaApi(this.route.meta, 'cronograma-etapa')}?cronograma_id=${cronograma_id}`);
this.Etapas[cronograma_id] = r.linhas.length
? r.linhas.map((x) => {
// mantendo comportamento legado
// eslint-disable-next-line eqeqeq
if (x.cronograma_origem_etapa && x.cronograma_origem_etapa.id == cronograma_id) {
delete x.cronograma_origem_etapa;
}
Expand Down Expand Up @@ -95,13 +99,21 @@ export const useEtapasStore = defineStore({
this.Etapas[cronograma_id] = { error };
}
},
// mantendo comportamento legado
// eslint-disable-next-line consistent-return
async getById(cronograma_id, etapa_id) {
try {
// mantendo comportamento legado
// eslint-disable-next-line @typescript-eslint/no-throw-literal
if (!cronograma_id) throw 'Cronograma inválido';
// mantendo comportamento legado
// eslint-disable-next-line @typescript-eslint/no-throw-literal
if (!etapa_id) throw 'Etapa inválida';
this.singleEtapa = { loading: true };
if (!this.Etapas[cronograma_id]) await this.getAll(cronograma_id);
this.singleEtapa = this.Etapas[cronograma_id].length
// mantendo comportamento legado
// eslint-disable-next-line eqeqeq
? this.Etapas[cronograma_id].find((u) => u.etapa_id == etapa_id)
: {};
return true;
Expand All @@ -110,20 +122,22 @@ export const useEtapasStore = defineStore({
}
},
async insert(cronograma_id, params) {
params.inicio_previsto = this.fieldToDate(params.inicio_previsto);
params.termino_previsto = this.fieldToDate(params.termino_previsto);
params.inicio_real = this.fieldToDate(params.inicio_real);
params.termino_real = this.fieldToDate(params.termino_real);
const r = await this.requestS.post(`${baseUrl}/${caminhoParaApi(this.route.meta, 'cronograma')}/${cronograma_id}/etapa`, params);
const newParams = { ...params };
newParams.inicio_previsto = this.fieldToDate(params.inicio_previsto);
newParams.termino_previsto = this.fieldToDate(params.termino_previsto);
newParams.inicio_real = this.fieldToDate(params.inicio_real);
newParams.termino_real = this.fieldToDate(params.termino_real);
const r = await this.requestS.post(`${baseUrl}/${caminhoParaApi(this.route.meta, 'cronograma')}/${cronograma_id}/etapa`, newParams);
if (r.id) return r.id;
return false;
},
async update(id, params) {
params.inicio_previsto = this.fieldToDate(params.inicio_previsto);
params.termino_previsto = this.fieldToDate(params.termino_previsto);
params.inicio_real = this.fieldToDate(params.inicio_real);
params.termino_real = this.fieldToDate(params.termino_real);
if (await this.requestS.patch(`${baseUrl}/${caminhoParaApi(this.route.meta, 'etapa')}/${id}`, params)) return true;
const newParams = { ...params };
newParams.inicio_previsto = this.fieldToDate(params.inicio_previsto);
newParams.termino_previsto = this.fieldToDate(params.termino_previsto);
newParams.inicio_real = this.fieldToDate(params.inicio_real);
newParams.termino_real = this.fieldToDate(params.termino_real);
if (await this.requestS.patch(`${baseUrl}/${caminhoParaApi(this.route.meta, 'etapa')}/${id}`, newParams)) return true;
return false;
},
async delete(id) {
Expand All @@ -133,15 +147,18 @@ export const useEtapasStore = defineStore({
return false;
},
async monitorar(params) {
if (await this.requestS.post(`${baseUrl}/${caminhoParaApi(this.route.meta,'cronograma-etapa')}`, params)) return true;
if (await this.requestS.post(`${baseUrl}/${caminhoParaApi(this.route.meta, 'cronograma-etapa')}`, params)) return true;
return false;
},
async getMonitoramento(cronograma_id, etapa_id) {
try {
// Mantendo comportamento legado
// eslint-disable-next-line @typescript-eslint/no-throw-literal
if (!cronograma_id) throw 'Cronograma inválido';
// eslint-disable-next-line @typescript-eslint/no-throw-literal
if (!etapa_id) throw 'Etapa inválida';
this.singleMonitoramento = { loading: true };
const r = await this.requestS.get(`${baseUrl}/${caminhoParaApi(this.route.meta,'cronograma-etapa')}?cronograma_id=${cronograma_id}&etapa_id=${etapa_id}`);
const r = await this.requestS.get(`${baseUrl}/${caminhoParaApi(this.route.meta, 'cronograma-etapa')}?cronograma_id=${cronograma_id}&etapa_id=${etapa_id}`);
this.singleMonitoramento = r.linhas.length ? r.linhas[0] : {};
return r.linhas.length ? r.linhas[0] : {};
} catch (error) {
Expand Down
37 changes: 22 additions & 15 deletions frontend/src/views/metas/AddEditEtapa.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,27 @@ const geolocalizaçãoPorToken = computed(() => (
}, {})
));

const valoresIniciais = computed(() => (singleEtapa.value?.loading
|| singleEtapa.value?.error
|| !singleEtapa.value?.id
? {
peso: 1,
percentual_execucao: 0,
endereco_obrigatorio: false,
geolocalizacao: [],
variavel: null,
const valoresIniciais = computed(() => {
if (singleEtapa.value?.loading || singleEtapa.value?.error || !singleEtapa.value?.id) {
return {
peso: 1,
percentual_execucao: 0,
endereco_obrigatorio: false,
geolocalizacao: [],
variavel: null,
inicio_previsto: '',
termino_previsto: '',
inicio_real: '',
termino_real: '',
};
}
: {
...singleEtapa.value?.etapa,
geolocalizacao: singleEtapa.value?.etapa?.geolocalizacao?.map((x) => x.token) || [],
}));

const { etapa } = singleEtapa.value;
return {
...etapa,
geolocalizacao: etapa.geolocalizacao?.map((x) => x.token) || [],
};
});

const {
errors, handleSubmit, isSubmitting, resetForm, setFieldValue, values,
Expand Down Expand Up @@ -733,7 +740,7 @@ watch(valoresIniciais, (novoValor) => {
:class="{ 'error': errors.inicio_previsto }"
maxlength="10"
placeholder="dd/mm/aaaa"
@keyup="maskDate"
@input="maskDate"
/>
<div class="error-msg">
{{ errors.inicio_previsto }}
Expand All @@ -748,7 +755,7 @@ watch(valoresIniciais, (novoValor) => {
:class="{ 'error': errors.termino_previsto }"
maxlength="10"
placeholder="dd/mm/aaaa"
@keyup="maskDate"
@input="maskDate"
/>
<div class="error-msg">
{{ errors.termino_previsto }}
Expand Down