Skip to content

Commit

Permalink
Fix frontend to new routes, add random code to email, add digidecs up…
Browse files Browse the repository at this point in the history
…loaded page
  • Loading branch information
TobiasDeBruijn committed Oct 23, 2024
1 parent 06281ec commit 161af74
Show file tree
Hide file tree
Showing 26 changed files with 697 additions and 219 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: release
on:
push:
tags:
- '**'

jobs:
build-server-musl:
name: build-server-musl
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: rustup toolchain install stable --profile minimal
- run: rustup target add x86_64-unknown-linux-musl --toolchain stable
- run: sudo apt install gcc musl-tools cmake clang
- uses: Swatinem/[email protected]
with:
workspaces: "server"
save-if: ${{ github.ref == 'refs/heads/master' }}
- run: cargo build --release --target x86_64-unknown-linux-musl
working-directory: server
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: server-x86_64-unknown-linux-musl
path: ./server/target/x86_64-unknown-linux-musl/release/digidecs

build-frontend:
name: build-frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set Node.js 21
uses: actions/setup-node@v3
with:
node-version: 21.x
- name: Run install
uses: borales/actions-yarn@v4
with:
dir: frontend
cmd: install
- name: Build
uses: borales/actions-yarn@v4
with:
dir: frontend
cmd: build
- run: tar -czf frontend.tar.gz dist/*
working-directory: frontend
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: frontend.tar.gz
path: ./frontend/frontend.tar.gz


create-release:
name: create-release
needs:
- build-server-musl
- build-frontend
runs-on: ubuntu-latest
steps:
- name: Download all workflow run artifacts
uses: actions/download-artifact@v3

- name: Create Release
id: create_release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false

- run: mv server-x86_64-unknown-linux-musl/digidecs server-x86_64-unknown-linux-musl/server-x86_64-unknown-linux-musl

- name: Release
uses: softprops/action-gh-release@v1
with:
files: |
server-x86_64-unknown-linux-musl/server-x86_64-unknown-linux-musl
frontend.tar.gz/frontend.tar.gz
53 changes: 53 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: test
on:
push: {}

jobs:
server-fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: rustup toolchain install stable --profile minimal
- run: rustup component add rustfmt
- uses: Swatinem/[email protected]
with:
workspaces: "server"
save-if: ${{ github.ref == 'refs/heads/master' }}
- run: cargo fmt --all --check
working-directory: server

server-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: rustup toolchain install stable --profile minimal
- uses: Swatinem/[email protected]
with:
workspaces: "server"
save-if: ${{ github.ref == 'refs/heads/master' }}
- run: cargo test
working-directory: server

server-clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: rustup toolchain install stable --profile minimal
- run: rustup component add clippy
- uses: Swatinem/[email protected]
with:
workspaces: "server"
save-if: ${{ github.ref == 'refs/heads/master' }}
- run: cargo clippy
working-directory: server

frontend-eslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install modules
working-directory: frontend
run: yarn
- name: Run eslint
working-directory: frontend
run: yarn eslint
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<link rel="icon" href="https://public.svsticky.nl/logos/hoofd_outline_kleur.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Sticky DigiDecs</title>
</head>
Expand Down
40 changes: 39 additions & 1 deletion frontend/src/plugins/locales/en.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,45 @@
import {Locale} from "@/plugins/locales/locale";

const EN: Locale = {

site_title: "DigiDecs",
error: "Something went wrong, please try again later",
home: {
title: "DigiDecs",
subtitle: "Declare digitally at Sticky",
invalidFieldsError: "One or multiple fields are incorreect",
form: {
name: "Naam",
iban: "IBAN",
email: "Email",
value: "Amount",
what: "What",
commission: "For what / which commission",
notes: "Notes",
files: "Receipts / Invoices",
filesExplanation: "Only .pdf, .jpg or .png files. You can submit multiple documents. Ensure the date, the (VAT) amount and the different products or services are clearly readable.",
checked: "I have checked everything and filled this form thruthfully",
rules: {
required: "Required",
ibanInvalid: "Invalid IBAN",
emailInvalid: "Invalid email address",
valueInvalid: "Invalid amount",
filesTooLarge: "The maximum file size is 15MB"
},
hints: {
name: "Treasurer",
email: "{'[email protected]'}",
iban: "NL13TEST0123456789",
value: "19,19",
what: "Digging Machine",
commission: "The board, obviously!"
}
},
submit: "Submit"
},
submitted: {
title: 'Success!',
description: "Your digidecs has been sent! If you haven't received your money back after 7 days, contact the treasurer"
}
}

export default EN;
5 changes: 4 additions & 1 deletion frontend/src/plugins/locales/locale.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
export interface Locale {
site_title: string,
error: string,
submitted: {
title: string,
description: string
},
home: {
title: string,
subtitle: string,
invalidFieldsError: string,
success: string,
form: {
name: string,
iban: string,
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/plugins/locales/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const NL: Locale = {
title: "DigiDecs",
subtitle: "Digitaal declareren bij Sticky",
invalidFieldsError: "Een of meerdere velden zijn onjuist ingevuld",
success: "Success! Je declaratie is ingestuurd. Mocht je na 5 werkdagen je geldf nog niet hebben ontvangen, neem dan contact op met de Penningmeester: [email protected].",
form: {
name: "Naam",
iban: "IBAN",
Expand All @@ -16,7 +15,7 @@ const NL: Locale = {
what: "Wat",
commission: "Waarvoor / Welke commissie",
notes: "Opmerkingen",
files: "Bonnetjes",
files: "Bonnetjes / Facturen",
filesExplanation: "Alleen .pdf, .jpg, en .png bestanden, je kan meerdere bestanden selecteren. Zorg dat de datum, het (btw) bedrag en de verschillende producten of diensten goed leesbaar zijn.",
checked: "Ik heb alles gecheckt en naar waarheid ingevuld",
rules: {
Expand All @@ -36,6 +35,10 @@ const NL: Locale = {
}
},
submit: "Verstuur"
},
submitted: {
title: "Succes!",
description: "Jouw digidecs is verstuurd! Mocht je na 7 dagen je geld nog niet terug hebben gekregen, neem dan contact op met de penningmeester"
}
}

Expand Down
4 changes: 4 additions & 0 deletions frontend/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const routes: Array<RouteRecordRaw> = [
{
path: '',
component: () => import('@/views/HomeView.vue')
},
{
path: 'complete',
component: () => import('@/views/SubmittedView.vue')
}
]
}
Expand Down
76 changes: 59 additions & 17 deletions frontend/src/scripts/digidecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ import {Result} from "@/scripts/core/result";
import {ApiError} from "@/scripts/core/error";
import {fetch1} from "@/scripts/core/fetch1";
import {server} from "@/main";
import {encode} from "base64-arraybuffer";


export class Digidecs {
static async digidecs(
trackingId: string;
attachments: string[]

constructor(trackingId: string, attachments: string[]) {
this.trackingId = trackingId;
this.attachments = attachments;
}

static async start(
name: string,
iban: string,
email: string,
Expand All @@ -14,19 +22,8 @@ export class Digidecs {
commission: string,
notes: string,
attachments: File[],
): Promise<Result<[], ApiError>> {
const attachmentsBase64 = await Promise.all(attachments.map(async attachment => {
const buffer = await attachment.arrayBuffer();
// const content = btoa(String.fromCharCode(...new Uint8Array(buffer)));
const content = encode(buffer);
return {
content: content,
name: attachment.name,
mime: attachment.type,
}
}));

const r = await fetch1(`${server}/api/digidecs`, {
): Promise<Result<Digidecs, ApiError>> {
const r = await fetch1(`${server}/api/digidecs/start`, {
method: 'POST',
headers: {
'content-type': 'application/json',
Expand All @@ -39,14 +36,59 @@ export class Digidecs {
what: what,
commission: commission,
notes: notes,
attachments: attachmentsBase64,
attachments: attachments.map((att) => {
return {
name: att.name,
mime: att.type,
};
}),
})
});
})

if(r.isOk()) {
interface StartedDigidecsResponse {
tracking_id: string;
attachments: {
name: string,
mime: string,
tracking_id: string,
}[]
}


return r.map1(async (response) => {
const r = <StartedDigidecsResponse> await response.json();
return new Digidecs(r.tracking_id, r.attachments.map((att) => att.tracking_id));
});
} else {
return Result.err(r.unwrapErr());
}
}

async upload_attachment(file: File, index: number): Promise<Result<[], ApiError>> {
const r = await fetch1(`${server}/api/digidecs/attachment?tracking_id=${this.trackingId}&attachment_tracking_id=${this.attachments[index]}`, {
method: 'POST',
body: file,
});

if(r.isOk()) {
return Result.ok([]);
} else {
return Result.err(r.unwrapErr());
}
}

async complete(): Promise<Result<[], ApiError>> {
const r = await fetch1(`${server}/api/digidecs/complete?tracking_id=${this.trackingId}`, {
method: 'POST',
});

if(r.isOk()) {
return Result.ok([]);
} else {
return Result.err(r.unwrapErr());
}
}


}
Loading

0 comments on commit 161af74

Please sign in to comment.