---
title: 重新規劃 Collection of Dashboard Today and app-dashboard action required
tags: v1
---
# 重新規劃 Collection of Dashboard Today and app-dashboard action required
[TOC]
# 先備知識
## MongoDB Collection: fio
fio = app = S.M.A.R.T. Contract
## MongoDB Collection: alpha_admin
使用者帳號資料
## survey === form
之前都叫 survey 現在都叫 form
所以 API 還是寫 survey,但就是 form 的意思
# UI 畫面
### Today

### action required

## 3大類12種狀態 (2021/7)
- 第一類:收到邀請、form 相關通知
- [x] 1. 所有 app: (等待被邀請)收到 app 邀請加入的通知
- user 可以接受("Accept invite" button)或拒絕("Reject invite" button)
- [x] 2. LearningCurve: 請填寫 Form
- [x] 3. LearningCurve: 通知 Admin/Owner,要去認證
- 通過("Authenticate" button)/拒絕("Reject" button) user 填寫 Form 的資料
- [x] 4. LearningCurve: 通知:你被拒絕了,請點擊 "Open form" button 重新填寫 Form
- [x] 5. 所有 app: (已經接受邀請) 提示接受邀請者,可以快速進入此 app 的 "Go to app" button
- 接受邀請 24 小時後,此通知就會消失
- 第二類:用量提醒
- [ ] 6. 你的 transation/data allowance 已用 75% 只剩下 25 % (可被 dismiss)
- [ ] 7. 你的 transation/data allowance 已用 90% 只剩下 10 % (不可被 dismiss)
- [ ] 8. 你的 transation/data allowance 已用 100% (不可被 dismiss)
- 第三類:首次安裝的新手提示
- [x] 9. learning curve - on first install - let's send your first form - send form (可被 dismiss)
- [x] 10. learning curve - on first install - invite a user - let's invite a user to you app - invite (可被 dismiss)
- [ ] 11. smart IP app - on first install - let's upload your first file - upload file (可被 dismiss)
- [ ] 12. nft app - on first install - let's create your first NFT - create NFT (可被 dismiss)
- 12種通知範例圖
[figma網址](https://www.figma.com/file/eHig3FCx9v95y1k3BnfYKj/FiO-Products-Design?node-id=5258%3A28788)
- 欄位說明
## 會觸發通知的 API 與時間點
- PUT `/fio/:id/invitation`
- PUT `/fio/:id/invitation/accept` (顯示 24 小時)
- PUT `/fio/:id/survey/send`
- S.M.A.R.T. Contract when status == awaiting-auth (學生填寫完 form 的時候)
- S.M.A.R.T. Contract when status == rejected (老師拒絕認證 form 的時候)
- POST `/subscribed`
## 想法
- 將所需呈現在同一個畫面上的資料通通放在同一個 Collection 裡面
## Jack 想法
- 所有通知都放到一個表叫 dashboard, 透過 username 去做 filter
## Collection 設計
```
dashboard_notification: [{
_id: 自動新增欄位,
level_app: true / false, // 如果是要在 app-dashboard 的通知則為 true
level_all_apps: true / false, // 如果是要在 /dashboard Today 的通知則為 true
display: true / false,
username: req.session.username,
status: Action required / Invit accepted / Rejected,
fio_id: fio._id,
fio_solution: fio.solution,
fio_name: fio.name,
link: fio.form,(Or 任何需要給出網址的)
action_type: invite / send_form / invite_send_form / accept / awaiting_auth / reject
user_type: user / approver
sender_email: micky@fio.one,(造成此通知的人的 email)
sender_name: Micky,
comment: "accrpt to join the app",
data: data, // 所有所需之資料 ex: 上鏈資訊
date: date,
}, ... ]
```
### action_type
| | 代表意思 |
|:---------------- |:----------------------------------------:|
| invite | User 被邀請進入某一個 app 時 |
| send_form | User 收到表單被要求填寫 |
| invite_send_form | 被邀請同時被寄了一份表單,須接受邀請才會寄出表單填寫通知 |
| accept | 接受邀請後 有進入 app 提示 |
| awaiting_auth | 等待 Admin/Owner 認證表單資料通知 |
| reject | User 填寫完的表單遭到拒絕後 重新填寫通知 |
| invite_guide | 進入 app 時 引導邀請 user 通知 |
| send_form_guide | 進入 app 時 引導寄出 form 通知 |
| transaction_limit |代表 transactions 超過 limit, comment 紀錄多少 percent |
| data_allowance_limit |代表 data_allowance 超過 limit, comment 紀錄多少 percent |
## 實作
- 不管舊通知,只加入新的通知
- 通知只會新增/刪除,不會修改
- 需要加開一隻刪除通知 API
## 刪除通知 API
- DELETE `/notification/dismiss/:notify_id`
## 等待認證通知
- 需要在上鏈邏輯的地方加上通知,也就是 `clsses/Obj.js` 這隻檔案加入可通知的 function
- 目標是任何 app 都可使用
### 規劃邏輯
- 將每個固定都有的 `fio._id,fio.solution,fio.name` 放入 function
- 可能有可能沒有的: 有的就給他相對的值 沒有則給 null
- link
- data
- 其餘常用的當作參數讓其他 app 也能使用
- level_app
- level_all_apps
- action_type
- comment
- status (沒給則是 'Action required')
### 實作等待認證通知
```
async notification(level_app, level_all_apps, action_type, comment, status, email){
let notifyObj = {
level_app: level_app, // 如果是要在 app-dashboard 的通知則為 true
level_all_apps: level_all_apps, // 如果是要在 /dashboard Today 的通知則為 true
display: true, // 預設為 ture 顯示
fio_id: this.fio._id,
fio_solution: this.fio.solution,
fio_name: this.fio.name,
link: this.fio.url ? this.fio.url : null,
username: email ? email : this.fio.username, // 給誰的通知
action_type: invite / send_form / invite_send_form / accept / awaiting_auth / reject
comment: comment ? comment : null,
status: status ? status : 'Action required', // Action required / Invit accepted
data: this.obj.vals ? this.obj.vals : null,
user_type: null,
sender_email: null, // email
sender_name: null,
date: new Date(),
}
await this.db.notification(notifyObj);
if(!this.fio.invitations) return;
this.fio.invitations.forEach( inv => {
if(inv.type !== 'apprpver') return;
notifyObj.username = inv.email;
// 這裡不加 await 因為不會影響到後面的資料 考慮到效能所以這樣做
this.db.notification(notifyObj);
});
}
```
## send form before inviting
- LearningCurve 可以再邀請前直接寄 form,但是要接受後才可以看到 form 通知
### 規劃
- 寄送表單時如果還沒邀請該對象,此時 action_type = invite_send_form,顯示 invite 通知
- 接受邀請後加入 send_form 通知,所以前端必須傳入 action_type
- 需更動 api
- `PUT /fio/:id/invitation/accept`
- `PUT /fio/:id/survey/send`
### 實作
```
```