Coder Social home page Coder Social logo

isnackable / saf-duty Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 19.73 MB

saf-duty; A Duty Roster planner for the Singapore Armed Forces (SAF). It's tailored for military uses. MIT License.

Home Page: https://afpn-cdo.vercel.app

License: MIT License

TypeScript 81.41% JavaScript 0.54% CSS 2.72% PLpgSQL 5.48% HTML 9.85%
national-service singapore army military

saf-duty's Introduction


Logo

SAF Duty Roster

A Duty Roster planner for the SAF. It's tailored for unit uses, however the code is customizable. MIT License.
View Demo »

About The Project

In SAF, soldiers are required to do duties, be it guard duty or 24hr ops duty. This project is tailored for unit, where they are required to do 24hr ops duty. The duty roster has these requirements:

  1. The duty roster should be spread out in a month of a calendar
  2. It is a 24-hour duty shift
  3. There must be a duty personnel for each day from the start to the end of the month
  4. There should not be any back-to-back duty for the same duty personnel.
  5. There should be an equal number of duties for everyone if possible.
  6. Personnel should be shuffled to avoid the first person always having the most number of duties
  7. Personnel can have block out dates where they should not have duties on the date they have blocked out.

preview

Features

  • Duty roster generation with points algorithm
  • Blockout dates management for personnel to avoid duties
  • Duty swap request with another personnel
  • Push notifications for reminders of duty and swap requests

Getting Started

To get a local copy up and running follow these simple example steps.

Prerequisites

You'll first need a Supabase project which can be made via the Supabase dashboard.

Clone and run locally

  1. Clone this project with Git

    git clone https://github.com/ISnackable/saf-duty
  2. Rename .env.local.example to .env.local and update the following:

    NEXT_PUBLIC_SUPABASE_URL=[INSERT SUPABASE PROJECT URL]
    NEXT_PUBLIC_SUPABASE_ANON_KEY=[INSERT SUPABASE PROJECT API ANON KEY]
    

    Both NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY can be found in your Supabase project's API settings

  3. You can now run the Next.js local development server:

    pnpm dev

    The server should now be running on localhost:3000.

Configuration

As much as this project aims to set up as seamlessly as possible, due to some limitation to Supabase, there are some config that has to be done manually.

Create vault secrets (Required)

Navigate to Project Vault settings in your Supabase Dashboard.

  1. Create a new secret with the name project_url.
  2. The secret value should be your project's url, you can find the it through the Project API settings.
  3. Repeat for the secret service_role_key.

Push Notification (Optional)

To Enable Push Notification with Web Push. You will need to deploy the Supabase Edge Function and create the database webhook manually.

1. Deploy the Supabase Edge Function

The database webhook handler to send push notifications is located in supabase/functions/push/index.ts. Deploy the function to your linked project and set the WEB_PUSH_PUBLIC_KEY, WEB_PUSH_PRIVATE_KEY & WEB_PUSH_EMAIL secret.

  1. supabase functions deploy push
  2. supabase secrets set --env-file .env.local

Note: The Public and Private keys secrets must be generated using the alastaircoote/webpush-webcrypto package.

2. Create the database webhook

Navigate to the Database Webhooks settings in your Supabase Dashboard.

  1. Enable and create a new hook with the name on_after_notifications_created.
  2. Conditions to fire webhook: Select the notifications table and tick the Insert event.
  3. Webhook configuration: Supabase Edge Functions.
  4. Edge Function: Select the push edge function and leave the method as POST and timeout as 1000.
  5. HTTP Headers: Click "Add new header" > "Add auth header with service key" and leave Content-type: application/json.
  6. Click "Create webhook".

3. Sending a push notification

When a new row is added in your notifications table, a push notification will be sent to the user who has subscribed to push notification.

  • Note: There's also a cron job for daily duty reminder if a user is subscribed to push notification.

     -- View all scheduled job.
     select * from cron.job;
    
     -- Or unschedule it if you want to disable it.
     select cron.unschedule('daily-roster-reminder');

License

Distributed under the MIT License. See LICENSE for more information.

Acknowledgements

saf-duty's People

Contributors

isnackable avatar

Stargazers

 avatar

Watchers

 avatar

saf-duty's Issues

BUG: Stale data when switching user account

When switching to another account, for example demo to user.
This only seem to happen on safari browser, on ios.
The pages will show the demo user's data instead of the user's data. It requires a manual refresh for the data to show.

A potential fix is to remove the @lib/demo.data file, and just query the demo data from sanity.

Edit: This might have to do with an issue with next-auth session not updating/clearing properly. See nextauthjs/next-auth#4612

[Feature Request]: Migrate to supabase and shadcn/ui

Below is the simple comparison of the two database as a service products.

supabase uses a relational database management system called PostgreSQL, it offers a free-tier hobby plan with:

  • Up to 500MB database & 1GB file storage
  • Up to 2GB bandwidth
  • Up to 50MB file uploads
  • Real time Postgres Changes
  • Unlimited API requests

sanity.io is a schemaless database built on top of Google cloud, it offers a free-tier plan with:

  • Up to 10k (1GB) Documents & 5GB assets
  • 10GB Bandwidth (per month)
  • Real-time data access
  • 5GB file uploads
  • 500k API requests (per month)

Additional notes:

Sanity is comparable to Firebase in how they store data, where firestore allows you to store “documents”. sanity.io is also the same and they basically use their plan. Thus, it may also be a viable option to switch to Firebase.

[BUG] Profile update account details

Description: Basically, when you update the profile account detail on another device, the changes of the user object may not reflect the latest details of account if they are already logged in.

Potential solution: Get the latest account details on first startup.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.