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

feat: allow editing groups #14

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 3 additions & 0 deletions my-app/src/lib/svgs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Useful SVGs
export const PENCIL_SVG =
'<svg fill="#FFF" width="25px" height="25px" viewBox="0 0 528.899 528.899"><g><path d="M328.883,89.125l107.59,107.589l-272.34,272.34L56.604,361.465L328.883,89.125z M518.113,63.177l-47.981-47.981 c-18.543-18.543-48.653-18.543-67.259,0l-45.961,45.961l107.59,107.59l53.611-53.611 C532.495,100.753,532.495,77.559,518.113,63.177z M0.3,512.69c-1.958,8.812,5.998,16.708,14.811,14.565l119.891-29.069 L27.473,390.597L0.3,512.69z"/></g></svg>';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { error } from '@sveltejs/kit';
import { error, redirect } from '@sveltejs/kit';
import type { Actions } from './$types';
import { categoryService, groupService } from '$lib/server/api';
import type { PageServerLoad } from './$types';
Expand Down Expand Up @@ -35,6 +35,6 @@ export const actions: Actions = {

const category: Category = { id, group_id, name, description, strategy };
await categoryService.save(category, cookies);
return { success: true };
redirect(302, `/groups/movements/${group_id}`);
}
};
7 changes: 5 additions & 2 deletions my-app/src/routes/groups/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import { title } from '$lib';
import { PENCIL_SVG } from '$lib/svgs';
import type { PageData } from './$types';

export let data: PageData;
Expand All @@ -25,9 +26,11 @@
{/if}
{#each data?.groups as group}
<article>
<header>{group.name}</header>
<header class="row">
<b style="padding: 15px">{group.name}</b>
<a class="secondary" href="/groups/details/{group.id}" role="button">{@html PENCIL_SVG}</a>
</header>
<p>{group.description}</p>
<!-- <a href="/groups/details/{group.id}" role="button" class="">Editar</a> -->
<a href="/groups/movements/{group.id}" role="button" class="outline">Moovimientos</a>
<a href="/groups/budgets/{group.id}" role="button" class="outline">Presupuestos</a>
</article>
Expand Down
4 changes: 1 addition & 3 deletions my-app/src/routes/groups/budgets/[[id=integer]]/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<script lang="ts">
import { title } from '$lib';
import { formatDateString, formatMoney } from '$lib/formatter';
import { PENCIL_SVG } from '$lib/svgs';
import type { PageServerData } from './$types';

export let data: PageServerData;

export const PENCIL_SVG =
'<svg fill="#FFF" width="25px" height="25px" viewBox="0 0 528.899 528.899"><g><path d="M328.883,89.125l107.59,107.589l-272.34,272.34L56.604,361.465L328.883,89.125z M518.113,63.177l-47.981-47.981 c-18.543-18.543-48.653-18.543-67.259,0l-45.961,45.961l107.59,107.59l53.611-53.611 C532.495,100.753,532.495,77.559,518.113,63.177z M0.3,512.69c-1.958,8.812,5.998,16.708,14.811,14.565l119.891-29.069 L27.473,390.597L0.3,512.69z"/></g></svg>';
</script>

<svelte:head>
Expand Down
11 changes: 6 additions & 5 deletions my-app/src/routes/groups/details/[[id=integer]]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import type { Actions } from './$types';
import { groupService } from '$lib/server/api';
import type { PageServerLoad } from './$types';

export const load: PageServerLoad = async ({ params }) => {
const group: Group = { name: '', description: '', id: 0, owner_id: 0 };
const id = params.id;
if (id) {
// TODO: load real group
export const load: PageServerLoad = async ({ params, cookies }) => {
const id = Number(params.id) || 0;
let group: Group = { name: '', description: '', id: 0, owner_id: 0 };
if (id !== 0) {
console.log(id);
group = await groupService.get(id, cookies)
}
return { group };
};
Expand Down
15 changes: 11 additions & 4 deletions my-app/src/routes/groups/details/[[id=integer]]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,37 @@
import type { PageData } from './$types';

export let data: PageData;
const edit = data.group.id !== 0;
</script>

<svelte:head>
<title>{title} - Nuevo Grupo</title>
</svelte:head>

<h2>Nuevo Grupo</h2>
<h2>
{#if edit}Editando{:else}Creando{/if} Grupo
</h2>
<form method="POST">
<fieldset>
<label>
Ingrese un nombre para el grupo
<input type="text" name="name" value={data.group.name} placeholder="Nombre" required />
<input type="text" name="name" value={data?.group.name} placeholder="Nombre" required />
</label>
<label>
Ingrese una descripción para el grupo
<input
type="text"
name="description"
value={data.group.description}
value={data?.group.description}
placeholder="Descripción"
required
/>
</label>
<button>Crear</button>
{#if edit}
<button>Editar</button>
{:else}
<button>Crear</button>
{/if}
<button type="button" class="outline" on:click={() => history.back()}>Cancelar</button>
</fieldset>
</form>