Skip to content

Commit e7e1c38

Browse files
authored
fix/feat: n/a gender option, proposal error messages / revoking proposals (#23)
* fix: n/a gender option * fix: proposal error messages show properly + propose on enter * fix: more descriptive message for invalid proposee, proper return for dupe proposal * feat: revoke proposals
1 parent d9b3456 commit e7e1c38

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

app/pages/proposals.vue

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async function handlePropose() {
5353
5454
router.go(0);
5555
} catch (err) {
56-
alert(err.message);
56+
alert(err.data);
5757
}
5858
}
5959
async function handleAccept(shortcode: string) {
@@ -65,7 +65,20 @@ async function handleAccept(shortcode: string) {
6565
6666
router.go(0);
6767
} catch (err) {
68-
alert(err.message);
68+
alert(err.data);
69+
}
70+
}
71+
72+
async function handleRevoke(shortcode: string) {
73+
try {
74+
await $fetch('/api/family/proposal', {
75+
method: 'DELETE',
76+
body: { shortcode }
77+
});
78+
79+
router.go(0);
80+
} catch (err) {
81+
alert(err.data);
6982
}
7083
}
7184
</script>
@@ -153,9 +166,20 @@ async function handleAccept(shortcode: string) {
153166
<div class="flex flex-col items-start">
154167
<strong>{{ proposal.proposee }}</strong>
155168
</div>
156-
<div class="flex items-start gap-3">
157-
<span class="cursor-pointer bg-yellow-400 p-1 text-sm text-white">
158-
Pending
169+
<div
170+
class="flex items-start gap-3"
171+
@click="handleRevoke(proposal.proposee)">
172+
<span
173+
class="group grid cursor-pointer bg-yellow-400 p-1 text-sm text-white duration-300 hover:bg-red-600 motion-reduce:transition-none">
174+
<!-- We shove them into the same cell in a grid to essentially overlay them for the transition. duration-300 is not inherited. -->
175+
<div
176+
class="col-start-1 row-start-1 duration-300 group-hover:opacity-0">
177+
Pending
178+
</div>
179+
<div
180+
class="col-start-1 row-start-1 opacity-0 duration-300 group-hover:opacity-100">
181+
Revoke?
182+
</div>
159183
</span>
160184
</div>
161185
</div>
@@ -168,6 +192,7 @@ async function handleAccept(shortcode: string) {
168192
</strong>
169193
<div class="flex gap-4">
170194
<input
195+
@keyup.enter="handlePropose"
171196
type="text"
172197
class="flex-grow"
173198
placeholder="e.g. nj421"

app/pages/survey.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ async function handleSubmit() {
160160

161161
<SurveyGroup label="Gender:" :required="true">
162162
<SurveySelect
163-
:options="['male', 'female', 'other', 'na']"
163+
:options="['male', 'female', 'other', 'n/a']"
164164
:labels="['Male', 'Female', 'Other', 'Prefer not to say']"
165165
name="gender"
166166
v-model="formData.gender"

hono/family/family.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ export const family = factory
124124
.where(eq(students.shortcode, proposee));
125125

126126
if (proposeeInDb.length == 0) {
127-
return ctx.text('Invalid proposee.', 400);
127+
return ctx.text(
128+
'Invalid proposee. Have they signed in to MaDs yet?',
129+
400
130+
);
128131
}
129132

130133
// 3 max proposals
@@ -140,10 +143,11 @@ export const family = factory
140143
}
141144

142145
// No dupe proposals
143-
currProposals.forEach(({ proposer: _proposer, proposee: _proposee }) => {
144-
if (_proposee == proposee)
146+
for (const proposal of currProposals) {
147+
if (proposal.proposee == proposee) {
145148
return ctx.text('You have already proposed to this user.', 400);
146-
});
149+
}
150+
}
147151

148152
await db.insert(proposals).values({
149153
proposer: proposer,

0 commit comments

Comments
 (0)