Skip to content

Commit 9ad15c2

Browse files
Invite users (#30)
* PR comments * Disable buttons and show correct buttons based on the provider * remove console log * PR comments * drone build * Faulty password messages * PR comments * Submodules merge
1 parent 8e534f5 commit 9ad15c2

File tree

7 files changed

+73
-15
lines changed

7 files changed

+73
-15
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:14-alpine as build
1+
FROM node:18-alpine as build
22

33
WORKDIR /app
44
COPY package*.json /app/

dev.Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:14-alpine
1+
FROM node:18-alpine
22

33
WORKDIR /app
44

pages/settings.tsx

+59-10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ const Settings: NextPage = () => {
2626
const [isOidc, setIsOidc] = useState(false);
2727
const [user, setUser] = useState<any>(null);
2828
const [activeAdminMessages, setActiveAdminMessages] = useState<AdminMessage[]>([]);
29+
const [isOidcInvitation, setIsOidcInvitation] = useState(false);
30+
const [backButtonDisabled, setBackButtonDisabled] = useState(false);
31+
const [messages, setMessages] = useState<any>(null);
2932
// Get ?flow=... from the URL
3033
const router = useRouter()
3134
const { flow: flowId, return_to: returnTo } = router.query
@@ -101,12 +104,50 @@ const Settings: NextPage = () => {
101104
setChangedFlow(initialFlow)
102105

103106
//prevent password change option display if sso
104-
if (["microsoft", "google"].includes(initialFlow.identity.metadata_public?.registration_scope?.provider_id)) {
105-
initialFlow.ui.nodes = initialFlow.ui.nodes.filter((node: UiNode) => node.group !== "password");
106-
setIsOidc(true);
107+
requestAnimationFrame(() => {
108+
if (["microsoft", "google"].includes(initialFlow.identity.metadata_public?.registration_scope?.provider_id)) {
109+
initialFlow.ui.nodes = initialFlow.ui.nodes.filter((node: UiNode) => node.group !== "password");
110+
setIsOidc(true);
111+
if (initialFlow.identity.metadata_public?.registration_scope?.invitation_sso) {
112+
setIsOidcInvitation(true);
113+
}
114+
const provider = initialFlow.identity.metadata_public?.registration_scope?.provider_id;
115+
if (provider === "google") {
116+
document.querySelector('button[value="Microsoft"]')?.setAttribute("class", "hidden");
117+
} else if (provider === "microsoft") {
118+
document.querySelector('button[value="Google"]')?.setAttribute("class", "hidden");
119+
}
120+
}
121+
});
122+
}, [initialFlow])
123+
124+
useEffect(() => {
125+
if (!changedFlow || !initialFlow) return;
126+
const firstNameButtonVal = (document.querySelector('input[name="traits.name.first"]') as HTMLInputElement)?.value;
127+
const lastNameButtonVal = (document.querySelector('input[name="traits.name.last"]') as HTMLInputElement)?.value;
128+
if (isOidc && isOidcInvitation) {
129+
if (firstNameButtonVal === "" || lastNameButtonVal === "") {
130+
setBackButtonDisabled(true);
131+
} else {
132+
setBackButtonDisabled(false);
133+
}
134+
} else {
135+
const emailButtonVal = (document.querySelector('input[name="traits.email"]') as HTMLInputElement)?.value;
136+
const passwordButtonVal = (document.querySelector('input[name="password"]') as HTMLInputElement)?.value;
137+
if (firstNameButtonVal === "" || lastNameButtonVal === "" || emailButtonVal === "" || passwordButtonVal === "") {
138+
setBackButtonDisabled(true);
139+
} else {
140+
setBackButtonDisabled(false);
141+
}
107142
}
143+
}, [isOidc, isOidcInvitation, initialFlow, changedFlow]);
108144

109-
}, [initialFlow])
145+
useEffect(() => {
146+
if (!changedFlow) return;
147+
if (changedFlow.ui.messages) {
148+
setMessages(changedFlow.ui.messages);
149+
}
150+
}, [changedFlow])
110151

111152
const onSubmit = (values: UpdateSettingsFlowBody) =>
112153
ory
@@ -142,8 +183,8 @@ const Settings: NextPage = () => {
142183
<div id="settings">
143184
<h2 className="title">Profile management and security settings</h2>
144185
<div className="form-container">
186+
<Messages messages={messages} />
145187
<h3 className="subtitle">Profile Settings</h3>
146-
<Messages messages={changedFlow?.ui.messages} />
147188
<Flow
148189
hideGlobalMessages
149190
onSubmit={onSubmit}
@@ -153,8 +194,7 @@ const Settings: NextPage = () => {
153194
</div>
154195
{!isOidc ?
155196
<div className="form-container">
156-
<h3 className="subtitle">Change password</h3>
157-
<Messages messages={changedFlow?.ui.messages} />
197+
<h3 className="subtitle">{flowId ? 'Set' : 'Change'} password</h3>
158198
<Flow
159199
hideGlobalMessages
160200
onSubmit={onSubmit}
@@ -166,7 +206,6 @@ const Settings: NextPage = () => {
166206
{containsBackupCodes ? (<div className="form-container">
167207
<h3 className="subtitle">Manage 2FA backup recovery codes</h3>
168208
<p>Recovery codes can be used in panic situations where you have lost access to your 2FA device.</p>
169-
<Messages messages={changedFlow?.ui.messages} />
170209
<Flow
171210
hideGlobalMessages
172211
onSubmit={onSubmit}
@@ -184,7 +223,6 @@ const Settings: NextPage = () => {
184223
href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&hl=en&gl=US"
185224
target="_blank">Android</a>).
186225
</p>
187-
<Messages messages={changedFlow?.ui.messages} />
188226
<Flow
189227
hideGlobalMessages
190228
onSubmit={onSubmit}
@@ -193,8 +231,19 @@ const Settings: NextPage = () => {
193231
/>
194232
</div>) : (<> </>)}
195233

234+
{isOidc && isOidcInvitation ? (<div className="form-container">
235+
<Flow
236+
hideGlobalMessages
237+
onSubmit={onSubmit}
238+
only="oidc"
239+
flow={changedFlow}
240+
/>
241+
</div>) : (<> </>)}
242+
196243
<div className="link-container">
197-
<a className="link" data-testid="forgot-password" href="/cognition">Back</a>
244+
<button className="link disabled:opacity-50 disabled:cursor-not-allowed" data-testid="forgot-password" disabled={backButtonDisabled} onClick={() => {
245+
router.push("/cognition")
246+
}}>Back</button>
198247
</div>
199248
</div>
200249
</div>

pkg/ui/Messages.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { displayMessage } from "@/util/helper-functions"
12
import { UiText } from "@ory/client"
23
import { Alert, AlertContent } from "@ory/themes"
34

@@ -9,7 +10,7 @@ export const Message = ({ message }: MessageProps) => {
910
return (
1011
<Alert severity={message.type === "error" ? "error" : "info"}>
1112
<AlertContent data-testid={`ui/message/${message.id}`} className={message.type == 'error' ? 'message error' : 'message success'}>
12-
{message.text}
13+
{displayMessage(message)}
1314
</AlertContent>
1415
</Alert>
1516
)

util/helper-functions.ts

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
const customMessageOverrides = {
2+
1060001: "Welcome to the app! You have successfully registered. Set your first, last name and password to continue.",
3+
};
4+
15
export function getValueIdentifier(selectedRole: any) {
26
let value = '';
37
if (selectedRole === 'engineer') {
@@ -58,4 +62,8 @@ export function prepareNodes(flow: any) {
5862
}
5963

6064
return filteredNodes;
65+
}
66+
67+
export function displayMessage(msg: any): string {
68+
return customMessageOverrides[msg.id] || msg.text;
6169
}

0 commit comments

Comments
 (0)