Skip to content

Commit

Permalink
Merge pull request #361 from ladesa-ro/Reorganizacao-Cursos
Browse files Browse the repository at this point in the history
Reorganizacao cursos
  • Loading branch information
guesant authored Nov 24, 2024
2 parents 0e58ec5 + fc557cd commit 099a06d
Show file tree
Hide file tree
Showing 62 changed files with 281 additions and 317 deletions.
8 changes: 4 additions & 4 deletions components/API/Context/setup-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const createApiContext = (shouldProvide = true) => {
data.value?.accessTokenExpires,
unref(status),
unref(lastRefreshedAt),
]);
]);

const whoAmIQuery = useQuery({
queryKey: whoAmIQueryKey,
Expand All @@ -30,10 +30,10 @@ export const createApiContext = (shouldProvide = true) => {
const whoAmI = computed(() => whoAmIQuery.data.value ?? null);

const usuario = computed(() => whoAmI.value?.usuario ?? null);
const vinculosAtivos = computed(() => whoAmI.value?.vinculosAtivos ?? []);
const perfisAtivos = computed(() => whoAmI.value?.perfisAtivos ?? []);

const resumoVinculos = computed(() => {
const todosOsVinculos = vinculosAtivos.value;
const todosOsVinculos = perfisAtivos.value;
return resumirVinculos(todosOsVinculos);
});

Expand All @@ -45,7 +45,7 @@ export const createApiContext = (shouldProvide = true) => {
//
whoAmI,
usuario,
vinculosAtivos,
perfisAtivos,
resumoVinculos,
//
whoAmIQuery,
Expand Down
12 changes: 6 additions & 6 deletions components/API/Context/typings.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type {
AuthWhoAmIResultDto,
UsuarioFindOneResultDto,
AuthWhoAmIResponse,
UsuarioFindOneResultView,
} from '@ladesa-ro/api-client-fetch';
import type { UseQueryReturnType } from '@tanstack/vue-query';
import type { ResumoVinculos } from '../Vinculos/ResumirVinculos';

export type DynamicWhoAmIResult<Strict extends boolean = true> =
AuthWhoAmIResultDto & {
AuthWhoAmIResponse & {
usuario: Strict extends true
? UsuarioFindOneResultDto
: UsuarioFindOneResultDto | null;
? AuthWhoAmIResponse
: UsuarioFindOneResultView | null;
};

export type IApiContext<
Expand All @@ -20,7 +20,7 @@ export type IApiContext<
resumoVinculos: ComputedRef<ResumoVinculos>;
whoAmI: ComputedRef<WhoAmI>;
usuario: ComputedRef<WhoAmI['usuario']>;
vinculosAtivos: ComputedRef<WhoAmI['vinculosAtivos']>;
vinculosAtivos: ComputedRef<WhoAmI['perfisAtivos']>;
//
whoAmIQuery: UseQueryReturnType<WhoAmI, Error>;
};
10 changes: 5 additions & 5 deletions components/API/Vinculos/ResumirVinculos.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {
CampusFindOneResultDto,
VinculoFindOneResultDto,
CampusFindOneResultView,
PerfilFindOneResultView
} from '@ladesa-ro/api-client-fetch';
import { type Dictionary } from 'lodash';
import groupBy from 'lodash/groupBy';
Expand All @@ -22,7 +22,7 @@ export type ResumoVinculos = {
* }
*/
mapaCargoCampi: {
[x: string]: CampusFindOneResultDto[];
[x: string]: CampusFindOneResultView[];
};

/**
Expand All @@ -31,10 +31,10 @@ export type ResumoVinculos = {
* professor: VinculoFindOneResultDto[]
* }
*/
mapaCargoVinculos: Dictionary<VinculoFindOneResultDto[]>;
mapaCargoVinculos: Dictionary<PerfilFindOneResultView[]>;
};

export const resumirVinculos = (todosOsVinculos: VinculoFindOneResultDto[]) => {
export const resumirVinculos = (todosOsVinculos: PerfilFindOneResultView[]) => {
const cargos = uniq(map(todosOsVinculos, 'cargo'));

const mapaCargoVinculos = groupBy(
Expand Down
9 changes: 3 additions & 6 deletions components/Section/Ambientes/Form/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const handleDelete = async () => {
);
if (resposta) {
await apiClient.ambientes.ambienteDeleteById({ id: id });
await apiClient.ambientes.ambienteDeleteOneById({ id: id });
await queryClient.invalidateQueries({ queryKey: ['ambientes'] });
$emit('close');
}
Expand Down Expand Up @@ -120,7 +120,7 @@ const onSubmit = handleSubmit(async (values: FormOutput) => {
});
id = ambienteCriado.id;
} else {
await apiClient.ambientes.ambienteUpdateById({
await apiClient.ambientes.ambienteUpdateOneById({
id: editId,
requestBody: {
Expand All @@ -132,11 +132,8 @@ const onSubmit = handleSubmit(async (values: FormOutput) => {
}
if (imagem) {
await apiClient.ambientes.ambienteSetCoverImage({
await apiClient.ambientes.ambienteGetImagemCapa({
id: id,
formData: {
file: imagem,
},
});
}
Expand Down
4 changes: 2 additions & 2 deletions components/Section/Ambientes/Grid/Item/Item.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script setup lang="ts">
import type { AmbienteFindOneResultDto } from '@ladesa-ro/api-client-fetch';
import type { AmbienteFindOneResultView } from '@ladesa-ro/api-client-fetch';
import {
ApiImageResource,
useApiImageRoute,
} from '../../../../../integrations/api/RoutesUtil';
type Props = {
isLoading?: boolean;
item?: AmbienteFindOneResultDto | null;
item?: AmbienteFindOneResultView | null;
};
const props = defineProps<Props>();
Expand Down
6 changes: 3 additions & 3 deletions components/Section/Blocos/Form/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const handleDelete = async () => {
);
if (resposta) {
await apiClient.blocos.blocoDeleteById({ id: id });
await apiClient.blocos.blocoDeleteOneById({ id: id });
await queryClient.invalidateQueries({ queryKey: ['blocos'] });
$emit('close');
}
Expand Down Expand Up @@ -110,7 +110,7 @@ const onSubmit = handleSubmit(async (values: FormOutput) => {
});
id = blocoCriado.id;
} else {
await apiClient.blocos.blocoUpdateById({
await apiClient.blocos.blocoUpdateOneById({
id: editId,
requestBody: {
Expand All @@ -122,7 +122,7 @@ const onSubmit = handleSubmit(async (values: FormOutput) => {
}
if (imagem) {
await apiClient.blocos.blocoSetCoverImage({
await apiClient.blocos.blocoSetImagemCapa({
id: id,
formData: {
file: imagem,
Expand Down
4 changes: 2 additions & 2 deletions components/Section/Blocos/Grid/Item/Item.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script setup lang="ts">
import type { BlocoFindOneResultDto } from '@ladesa-ro/api-client-fetch';
import type { BlocoFindOneResultView } from '@ladesa-ro/api-client-fetch';
import {
ApiImageResource,
useApiImageRoute,
} from '../../../../../integrations/api/RoutesUtil';
type Props = {
isLoading?: boolean;
item?: BlocoFindOneResultDto | null;
item?: BlocoFindOneResultView | null;
};
const props = defineProps<Props>();
Expand Down
89 changes: 27 additions & 62 deletions components/Section/Calendario/Forms/Form1.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts" setup>
import { useQueryClient } from '@tanstack/vue-query';
import { useForm } from 'vee-validate';
import { computed } from 'vue';
import { computed, reactive, toRef } from 'vue';
import * as yup from 'yup';
import { useApiClient, useApiCursosFindOne } from '~/composables';
Expand All @@ -17,7 +17,6 @@ const closeForm = () => {
$emit('close');
};
type Props = {
editId?: string | null;
};
Expand All @@ -26,55 +25,33 @@ const props = withDefaults(defineProps<Props>(), {
editId: null,
});
//
const editIdRef = toRef(props, 'editId');
const apiClient = useApiClient();
const queryClient = useQueryClient();
const { curso: currentCurso } = await useApiCursosFindOne(editIdRef);
type FormValues = {
imagem: Blob | null | undefined;
modalidade: {
id: string | null;
};
campus: {
id: string | null;
};
ofertaFormacao: { id: string | null };
campus: { id: string | null };
nome: string;
nomeAbreviado: string;
};
type FormOutput = {
imagem: Blob | null | undefined;
modalidade: {
id: string;
};
campus: {
id: string;
};
ofertaFormacao: { id: string };
campus: { id: string };
nome: string;
nomeAbreviado: string;
};
const initialFormValues = reactive({
const initialFormValues = reactive<FormValues>({
imagem: null,
modalidade: {
id: currentCurso.value?.modalidade?.id ?? null,
},
campus: {
id: currentCurso.value?.campus?.id ?? null,
},
ofertaFormacao: { id: currentCurso.value?.ofertaFormacao?.id ?? null },
campus: { id: currentCurso.value?.campus?.id ?? null },
nome: currentCurso.value?.nome ?? '',
nomeAbreviado: currentCurso.value?.nomeAbreviado ?? '',
});
Expand All @@ -89,21 +66,20 @@ const handleDelete = async () => {
);
if (resposta) {
await apiClient.cursos.cursoDeleteById({ id: id });
await apiClient.cursos.cursoDeleteOneById({ id });
await queryClient.invalidateQueries({ queryKey: ['cursos'] });
$emit('close');
}
};
const schema = yup.object().shape({
imagem: yup.mixed().nullable().optional(),
modalidade: yup.object().shape({
id: yup.string().required('Modalidade é obrigatório!'),
ofertaFormacao: yup.object().shape({
id: yup.string().required('Oferta Formação é obrigatória!'),
}),
campus: yup.object().shape({
id: yup.string().required('Campus é obrigatório!'),
}),
nome: yup.string().required('Nome do bloco é obrigatório!'),
nomeAbreviado: yup
.string()
Expand All @@ -113,7 +89,6 @@ const schema = yup.object().shape({
const {
resetForm,
handleSubmit,
setFieldValue,
values: formValues,
} = useForm<FormValues, FormOutput>({
validationSchema: schema,
Expand All @@ -134,23 +109,20 @@ const onSubmit = handleSubmit(async (values: FormOutput) => {
id = cursoCriado.id;
} else {
await apiClient.cursos.cursoUpdateById({
await apiClient.cursos.cursoUpdateOneById({
id: editId,
requestBody: {
...values,
...data,
},
});
id = editId;
}
if (imagem) {
await apiClient.cursos.cursoSetCoverImage({
id: id,
formData: {
file: imagem,
},
await apiClient.cursos.cursoSetImagemCapa({
id,
formData: { file: imagem },
});
}
Expand Down Expand Up @@ -181,7 +153,6 @@ const nome = computed({
<v-divider class="my-4" />

<div class="form-body modal-form">

<VVTextField
v-model="nome"
type="text"
Expand All @@ -191,38 +162,32 @@ const nome = computed({
/>

<VVAutocomplete
name="year.id"
label="Ano letivo"
placeholder="Selecione um ano"
:items="years"
class="xl:max-w-[100%]"
/>
name="year.id"
label="Ano letivo"
placeholder="Selecione um ano"
:items="years"
class="xl:max-w-[100%]"
/>

<VVAutocompleteAPIModalidade name="modalidade.id" />
<VVAutocompleteAPIOfertaFormacao
v-model="formValues.ofertaFormacao.id"
name="ofertaFormacao.id"
label="Oferta de Formação"
/>

<VVAutocompleteAPICurso name="curso.id" />
</div>

<v-divider />

<div class="form-footer button-group">
<div class="form-footer button-group">
<UIButtonModalCancelButton @click="closeForm" />
<UIButtonModalAdvancedButton @click="nextForm" />
</div>
</div>
</v-form>
</template>

<style scoped>
/* .form {
overflow: hidden;
}
.form-body {
overflow: auto;
} */
.form {
overflow: auto;
}
Expand Down
Loading

0 comments on commit 099a06d

Please sign in to comment.