Skip to content

Commit

Permalink
feat: add toggle for standardizeUsername
Browse files Browse the repository at this point in the history
  • Loading branch information
laporchen committed Sep 18, 2024
1 parent 7f1ddb7 commit 8753ad2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@
"content": "From the second row, fill each member's data in each row",
"caution": "Note that if we find a user with the same username or email in the database, the user will still be added into course, BUT other information will not be update UNLESS you check the checkbox below."
},
"forceUpdate": "Force update existing users' data"
"forceUpdate": "Force update existing users' data",
"standardizeUsername": "Standardize Username (uppercase)"
}
},
"courses": {
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@
"content": "第二列開始每列為一個成員的資料",
"caution": "請注意若系統已有使用者使用了 CSV 中的 username 或 email,則該學生依舊會被加入課程,但其他欄位的資訊不會更新, 若要強制更新他的資訊請勾選下方的選項。"
},
"forceUpdate": "強制更新已存在的使用者的資訊"
"forceUpdate": "強制更新已存在的使用者的資訊",
"standardizeUsername": "統一使用者名稱(字母大寫)"
}
},
"courses": {
Expand Down
16 changes: 14 additions & 2 deletions src/pages/course/[name]/members.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const rolesCanCreateCourse = [UserRole.Admin, UserRole.Teacher];
const isOpen = ref(false);
const newMembers = ref<File | null>();
const shouldStandardizeUsername = ref(true);
const newMembersCSVString = ref("");
const forceUpdate = ref(false);
const isProcessingSignup = ref(false);
Expand Down Expand Up @@ -72,7 +73,7 @@ watch(newMembers, () => {
const reader = new FileReader();
reader.onload = (evt) => {
if (typeof evt.target?.result !== "string") return;
newMembersCSVString.value = standardizeUsername(evt.target?.result || "");
newMembersCSVString.value = evt.target?.result;
const rows = newMembersCSVString.value.split("\n");
previewCSV.value.headers = rows[0].split(",");
Expand All @@ -83,9 +84,13 @@ watch(newMembers, () => {
async function submit() {
if (!newMembersCSVString.value) return;
isProcessingSignup.value = true;
const csv = shouldStandardizeUsername.value
? standardizeUsername(newMembersCSVString.value)
: newMembersCSVString.value;
try {
await api.Auth.batchSignup({
newUsers: newMembersCSVString.value,
newUsers: csv,
force: forceUpdate.value,
course: route.params.name as string,
});
Expand Down Expand Up @@ -180,6 +185,13 @@ async function submit() {

<div class="my-4" />

<div class="form-control">
<label class="label cursor-pointer">
<span class="label-text">{{ $t("course.members.standardizeUsername") }}</span>
<input v-model="shouldStandardizeUsername" type="checkbox" class="checkbox-primary checkbox" />
</label>
</div>

<div class="alert alert-error shadow-lg" v-if="errorMsg">
<div>
<i-uil-times-circle />
Expand Down

0 comments on commit 8753ad2

Please sign in to comment.