Skip to content

Commit 51c5643

Browse files
Email templates UI (#608)
* initial devcontainer setup * basic email template get, update and delete * template creation ui * remove error printing * convert all plain text responses to `AppMessage` * fix email template card margins * wrap `params` prop type with `Promise<>` * actions workflows for nextjs * add @radix-ui/react-alert-dialog * add @radix-ui/react-tabs * only run workflows when relevant paths modified
1 parent 4b53703 commit 51c5643

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1370
-73
lines changed

.devcontainer/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM mcr.microsoft.com/devcontainers/base:ubuntu
2+
3+
# Setup packages
4+
RUN apt update && export DEBIAN_FRONTEND=noninteractive \
5+
&& apt -y install --no-install-recommends libssl-dev pkgconf build-essential postgresql-client
6+
7+
# Note: Rust, Node.js, and Bun are installed via devcontainer.json features.
8+
# sqlx-cli will be installed in post-create.sh to ensure it uses the correct cargo environment.

.devcontainer/devcontainer.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "Chaos Dev Container",
3+
"dockerComposeFile": "docker-compose.yml",
4+
"service": "app",
5+
"workspaceFolder": "/workspaces/chaos",
6+
"features": {
7+
"ghcr.io/devcontainers/features/node:1": {
8+
"version": "lts"
9+
},
10+
"ghcr.io/devcontainers/features/rust:1": {
11+
"version": "latest"
12+
},
13+
"ghcr.io/michidk/devcontainers-features/bun:1": {
14+
"version": "latest"
15+
}
16+
},
17+
"customizations": {
18+
"vscode": {
19+
"extensions": [
20+
"rust-lang.rust-analyzer",
21+
"DBCode.dbcode"
22+
]
23+
}
24+
},
25+
"postCreateCommand": "bash .devcontainer/post-create.sh",
26+
"remoteUser": "vscode"
27+
}

.devcontainer/docker-compose.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
services:
2+
app:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
volumes:
7+
- ..:/workspaces/chaos:cached
8+
# Overrides default command so things don't shut down after the process ends.
9+
command: sleep infinity
10+
# Use the same network as the db service to access it via localhost
11+
network_mode: service:db
12+
13+
db:
14+
image: postgres:17
15+
restart: unless-stopped
16+
environment:
17+
POSTGRES_USER: postgres
18+
POSTGRES_PASSWORD: password
19+
POSTGRES_DB: chaos
20+
volumes:
21+
- chaos-postgres-data:/var/lib/postgresql/data
22+
# Forward ports: 5432 (db), 3000 (frontend), 8080 (backend)
23+
ports:
24+
- "5433:5432"
25+
- "3000:3000"
26+
- "8080:8080"
27+
28+
volumes:
29+
chaos-postgres-data:

.devcontainer/post-create.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "Starting post-create setup..."
5+
6+
# Create backend/.env
7+
echo "Creating backend/.env..."
8+
cat << 'EOF' > backend/.env
9+
DATABASE_URL="postgres://postgres:password@localhost:5432/chaos"
10+
JWT_SECRET="test_secret"
11+
GOOGLE_CLIENT_ID="test"
12+
GOOGLE_CLIENT_SECRET="test"
13+
GOOGLE_REDIRECT_URI="http://localhost:3000/auth/callback"
14+
S3_BUCKET_NAME="chaos-storage"
15+
S3_ACCESS_KEY="test_access_key"
16+
S3_SECRET_KEY="test_secret_key"
17+
S3_ENDPOINT="https://chaos-storage.s3.ap-southeast-1.amazonaws.com"
18+
S3_REGION_NAME="ap-southeast-1"
19+
DEV_ENV="dev"
20+
SMTP_USERNAME="test_username"
21+
SMTP_PASSWORD="test_password"
22+
SMTP_HOST="smtp.example.com"
23+
EOF
24+
25+
# Install sqlx-cli if not present
26+
if ! command -V sqlx &> /dev/null; then
27+
echo "Installing sqlx-cli..."
28+
cargo install sqlx-cli --no-default-features --features native-tls,postgres
29+
fi
30+
31+
# Wait for Postgres
32+
echo "Waiting for Postgres..."
33+
until PGPASSWORD=password psql -h "db" -U "postgres" -d "chaos" -c '\q' 2>/dev/null; do
34+
echo "Waiting for postgres at db:5432..."
35+
sleep 2
36+
done
37+
38+
# Setup DB
39+
echo "Setting up database..."
40+
cd backend
41+
42+
# Create database if not exists
43+
sqlx database create || true
44+
sqlx migrate run
45+
46+
echo "Setup complete!"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Frontend (Next.js)
2+
3+
on:
4+
pull_request:
5+
branches: [main, "renovate/*", "CHAOS-224-KHAOS-rewrite", "CHAOS-571-integrate-be-fe", "CHAOS-598-nextjs"]
6+
paths:
7+
- "frontend-nextjs/**"
8+
- ".github/workflows/frontend-nextjs.yml"
9+
push:
10+
branches: ["renovate/*"]
11+
paths:
12+
- "frontend-nextjs/**"
13+
- ".github/workflows/frontend-nextjs.yml"
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
defaults:
19+
run:
20+
working-directory: ./frontend-nextjs
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Setup Bun
26+
uses: oven-sh/setup-bun@v1
27+
with:
28+
bun-version: latest
29+
30+
- name: Install dependencies
31+
run: bun install
32+
33+
- name: Build
34+
run: bun run build
35+
env:
36+
NEXT_PUBLIC_APP_URL: http://localhost:3000
37+
NEXT_OAUTH_CALLBACK_URL: http://localhost:8080/auth/google
38+
NEXT_API_BASE_URL: https://localhost:8080

.github/workflows/rust.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ name: Rust
22

33
on:
44
pull_request:
5-
branches: [main, "renovate/*", "CHAOS-224-KHAOS-rewrite", "CHAOS-571-integrate-be-fe"]
5+
branches: [main, "renovate/*", "CHAOS-224-KHAOS-rewrite", "CHAOS-571-integrate-be-fe", "CHAOS-598-nextjs"]
6+
paths:
7+
- "backend/**"
8+
- ".github/workflows/rust.yml"
69
push:
710
branches: ["renovate/*"]
11+
paths:
12+
- "backend/**"
13+
- ".github/workflows/rust.yml"
814

915
env:
1016
CARGO_TERM_COLOR: always

backend/database-seeding/src/seeder.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,16 @@ pub async fn seed_database(mut seeder: Seeder) {
325325
.await.expect("Failed seeding Rating 3");
326326

327327
let template =
328-
"Hello {{name}},
328+
"
329+
Hello {{name}},
329330
330-
Congratulations! You have been selected for the role of {{role}} at {{organisation_name}} for our {{campaign_name}}.
331+
Congratulations! You have been selected for the role of {{role}} at {{organisation_name}} for our {{campaign_name}}.
331332
332-
Please confirm your acceptance by {{expiry_date}}.
333+
Please confirm your acceptance by {{expiry_date}}.
333334
334-
Best regards,
335-
The {{organisation_name}} Team".to_string();
335+
Best regards,
336+
The {{organisation_name}} Team
337+
".to_string();
336338

337339

338340
let email_template_id = Organisation::create_email_template(

backend/server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ chrono = { version = "0.4", features = ["serde"] }
2222
oauth2 = "4.4"
2323
log = "0.4"
2424
uuid = { version = "1.5", features = ["serde", "v4"] }
25+
nanoid = "0.4.0"
2526
rust-s3 = "0.34.0"
2627
rs-snowflake = "0.6"
2728
jsonwebtoken = "9.1"

backend/server/src/constants.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub const NANOID_ALPHABET: [char; 16] = [
2+
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'a', 'b', 'c', 'd', 'e', 'f'
3+
];

backend/server/src/handler/answer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! - Managing role-specific answers
77
88
use crate::models::answer::{Answer, NewAnswer};
9-
use crate::models::app::AppState;
9+
use crate::models::app::{AppMessage, AppState};
1010
use crate::models::auth::{AnswerOwner, ApplicationOwner, ApplicationOwnerOrReviewer};
1111
use crate::models::error::ChaosError;
1212
use crate::models::transaction::DBTransaction;
@@ -141,7 +141,7 @@ impl AnswerHandler {
141141

142142
transaction.tx.commit().await?;
143143

144-
Ok((StatusCode::OK, "Successfully updated answer"))
144+
Ok(AppMessage::OkMessage("Successfully updated answer"))
145145
}
146146

147147
/// Deletes an answer.
@@ -169,6 +169,6 @@ impl AnswerHandler {
169169

170170
transaction.tx.commit().await?;
171171

172-
Ok((StatusCode::OK, "Successfully deleted answer"))
172+
Ok(AppMessage::OkMessage("Successfully deleted answer"))
173173
}
174174
}

0 commit comments

Comments
 (0)