Skip to content

Commit

Permalink
✨ Allow updating people
Browse files Browse the repository at this point in the history
  • Loading branch information
dmoyadev committed May 28, 2024
1 parent 6bd8cf1 commit ffdf9d8
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 208 deletions.
5 changes: 4 additions & 1 deletion src/layouts/OnboardingLayout.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<script setup lang="ts">
import BaseButton from '@/components/button/BaseButton.vue';
import { ButtonForm, ButtonMode } from '@/components/button/BaseButton.types.ts';
import { usePeopleService } from '@/modules/people/composables/usePeopleService.ts';
const { people } = usePeopleService();
</script>

<template>
Expand All @@ -15,7 +18,7 @@ import { ButtonForm, ButtonMode } from '@/components/button/BaseButton.types.ts'
<BaseButton
:button-form="ButtonForm.INLINE"
:mode="ButtonMode.CLEAR"
to="/people/__new__"
:to="people.length ? '/' : '/people/__new__'"
>
Saltar
</BaseButton>
Expand Down
5 changes: 3 additions & 2 deletions src/modules/app/composables/useDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
getDoc,
getDocs,
query,
setDoc,
updateDoc,
where,
} from 'firebase/firestore';
import { ref } from 'vue';
Expand Down Expand Up @@ -123,10 +123,11 @@ export function useDB(collectionName: string) {
const elementSnap = await getDoc(elementRef);
if (elementSnap.exists() && typeof element === 'object') {
const date: Timestamp = Timestamp.now();
return await setDoc(elementRef, {
await updateDoc(elementRef, {
...element,
updated_at: date,
});
return elementRef;
}
}

Expand Down
19 changes: 16 additions & 3 deletions src/modules/app/pages/HomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,23 @@ const { people, loading } = usePeopleService();

<!-- ✅ Success state -->
<template v-else>
<p style="background: var(--color-success); color: var(--color-success-accent)">
{{ people.find(p => p.id === $route.query?.created)?.name || 'ni idea' }} se ha creado!
<p
v-if="$route.query?.created"
style="background: var(--color-success); color: var(--color-success-accent)"
>
{{ people.find(p => p.id === $route.query.created)?.name || 'ni idea' }} se ha creado!
</p>
<p v-for="person in people" :key="person.id">
<p
v-if="$route.query?.updated"
style="background: var(--color-success); color: var(--color-success-accent)"
>
{{ people.find(p => p.id === $route.query.updated)?.name || 'ni idea' }} se ha actualizado!
</p>

<p
v-for="person in people" :key="person.id"
@click="$router.push(`/people/${person.id}`)"
>
{{ person }}
<br>
<br>
Expand Down
6 changes: 3 additions & 3 deletions src/modules/people/composables/usePeopleService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export function usePeopleService() {
people.value = await getBy<Person>();
}

async function createPerson(person: Person) {
const personRef = await upsert<Person>(person);
async function upsertPerson(person: Person) {
const personRef = await upsert<Person>(person, person.id);
await getPeople();
return personRef;
}
Expand All @@ -27,6 +27,6 @@ export function usePeopleService() {
people,
loading,
getPeople,
createPerson,
upsertPerson,
};
}
188 changes: 0 additions & 188 deletions src/modules/people/pages/PersonCreate.vue

This file was deleted.

Loading

0 comments on commit ffdf9d8

Please sign in to comment.