Skip to content

Commit 0f531d7

Browse files
mickenordinantoonp
authored andcommitted
refactor(OCM-Invites): unify accept form into single invite input
- Replace separate Provider/Token fields with one `invite` text field. - Parse invite string as `token@provider`, splitting on the last `@`. - Emit parsed `{ provider, token }` on accept. - Show validation error if invite is malformed. - Updated template and helper text accordingly. Signed-off-by: Micke Nordin <[email protected]>
1 parent eda9c36 commit 0f531d7

File tree

1 file changed

+86
-62
lines changed

1 file changed

+86
-62
lines changed

src/components/Ocm/OcmAcceptForm.vue

Lines changed: 86 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,96 @@
11
<template>
2-
<div class="ocm_manual_form">
3-
<h5 class="">
4-
{{
5-
t(
6-
"contacts",
7-
"Accept an invite from someone outside your organisation to collaborate."
8-
)
9-
}}
10-
</h5>
11-
<p>
12-
{{
13-
t(
14-
"contacts",
15-
"After you have accepted the invite, both of you will appear in each others' contacts list and you can start sharing data with each other."
16-
)
17-
}}
18-
</p>
19-
<div class="ocm_manual_inputs">
20-
<NcTextField v-model="provider" label="Provider" type="text" />
21-
<NcTextField v-model="token" label="Token" type="text" />
22-
<div class="ocm_manual_buttons">
23-
<Button @click="accept">
24-
<template #icon>
25-
<IconLoading v-if="loadingUpdate" :size="20" />
26-
<IconCheck v-else :size="20" />
27-
</template>
28-
{{ t("contacts", "Accept") }}
29-
</Button>
30-
<Button @click="cancel">
31-
<template #icon>
32-
<IconLoading v-if="loadingUpdate" :size="20" />
33-
<IconCancel v-else :size="20" />
34-
</template>
35-
{{ t("contacts", "Cancel") }}
36-
</Button>
37-
</div>
38-
</div>
39-
</div>
2+
<div class="ocm_manual_form">
3+
<h5 class="">
4+
{{
5+
t(
6+
"contacts",
7+
"Accept an invite from someone outside your organisation to collaborate."
8+
)
9+
}}
10+
</h5>
11+
<p>
12+
{{
13+
t(
14+
"contacts",
15+
"After you have accepted the invite, both of you will appear in each others' contacts list and you can start sharing data with each other."
16+
)
17+
}}
18+
</p>
19+
20+
<div class="ocm_manual_inputs">
21+
<NcTextField
22+
v-model="invite"
23+
label="Invite"
24+
type="text"
25+
:error="Boolean(error)"
26+
:helper-text="error || 'Paste `token@provider` or the full invite string'"
27+
/>
28+
29+
<div class="ocm_manual_buttons">
30+
<Button @click="accept">
31+
<template #icon>
32+
<IconLoading v-if="loadingUpdate" :size="20" />
33+
<IconCheck v-else :size="20" />
34+
</template>
35+
{{ t("contacts", "Accept") }}
36+
</Button>
37+
<Button @click="cancel">
38+
<template #icon>
39+
<IconLoading v-if="loadingUpdate" :size="20" />
40+
<IconCancel v-else :size="20" />
41+
</template>
42+
{{ t("contacts", "Cancel") }}
43+
</Button>
44+
</div>
45+
</div>
46+
</div>
4047
</template>
4148

4249
<script>
43-
import NcTextField from '@nextcloud/vue/components/NcTextField'
44-
import NcButton from '@nextcloud/vue/components/NcButton'
50+
import NcTextField from "@nextcloud/vue/components/NcTextField";
51+
import NcButton from "@nextcloud/vue/components/NcButton";
4552
4653
export default {
47-
name: 'OcmAcceptForm',
48-
components: {
49-
NcTextField,
50-
NcButton,
51-
},
52-
data() {
53-
return {
54-
provider: '',
55-
token: '',
56-
}
57-
},
58-
methods: {
59-
accept() {
60-
this.$emit('accept', { provider: this.provider, token: this.token })
61-
},
62-
cancel() {
63-
this.$emit('cancel')
64-
},
65-
},
66-
}
67-
</script>
54+
name: "OcmAcceptForm",
55+
components: { NcTextField, NcButton },
56+
data() {
57+
return {
58+
invite: "",
59+
error: "",
60+
};
61+
},
62+
methods: {
63+
parseInvite(str) {
64+
const s = String(str || "").trim();
65+
const idx = s.lastIndexOf("@");
66+
if (idx === -1) {
67+
throw new Error("No @ found in invite");
68+
}
69+
const token = s.slice(0, idx);
70+
const provider = s.slice(idx + 1);
71+
if (!token || !provider) {
72+
throw new Error("Malformed invite");
73+
}
74+
return { provider, token };
75+
},
6876
77+
accept() {
78+
this.error = "";
79+
try {
80+
const { provider, token } = this.parseInvite(this.invite);
81+
this.$emit("accept", { provider, token });
82+
} catch (e) {
83+
this.error = "Invalid invite format";
84+
this.$emit("parse-error", { message: this.error });
85+
}
86+
},
87+
88+
cancel() {
89+
this.$emit("cancel");
90+
},
91+
},
92+
};
93+
</script>
6994
<style lang="scss" scoped>
7095
.ocm_manual_buttons {
7196
display: flex;
@@ -77,7 +102,6 @@ export default {
77102
flex-direction: column;
78103
gap: 1rem;
79104
margin: 1em;
80-
81105
p {
82106
margin-bottom: 1em;
83107
}

0 commit comments

Comments
 (0)