|
1
|
|
|
import { Locales } from "./localize"; |
|
2
|
|
|
|
|
3
|
|
|
/* eslint-disable no-useless-escape */ |
|
4
|
|
|
function stripTrailingSlash(str: string): string { |
|
5
|
|
|
return str.endsWith("/") ? str.slice(0, -1) : str; |
|
6
|
|
|
} |
|
7
|
|
|
|
|
8
|
|
|
function isValidUrl(str: string): boolean { |
|
9
|
|
|
if (str.startsWith("http://") || str.startsWith("https://")) { |
|
10
|
|
|
try { |
|
11
|
|
|
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars |
|
12
|
|
|
const url = new URL(str); |
|
13
|
|
|
} catch (_) { |
|
14
|
|
|
return false; |
|
15
|
|
|
} |
|
16
|
|
|
return true; |
|
17
|
|
|
} |
|
18
|
|
|
return false; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
export function baseUrl(): string { |
|
22
|
|
|
const base = document.querySelector("meta[name='base-url']"); |
|
23
|
|
|
if (base !== null) { |
|
24
|
|
|
return stripTrailingSlash(base.getAttribute("content") ?? ""); |
|
25
|
|
|
} |
|
26
|
|
|
return ""; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
export function basePathname(): string { |
|
30
|
|
|
const base = baseUrl(); |
|
31
|
|
|
return isValidUrl(base) ? new URL(baseUrl()).pathname : ""; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
export function baseApiUrl(version = 1): string { |
|
35
|
|
|
return `${baseUrl()}/api/v${version}`; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* |
|
40
|
|
|
* @param imgFile The name of the img file, not inluding the /images/ path. |
|
41
|
|
|
*/ |
|
42
|
|
|
export function imageUrl(imgFile: string): string { |
|
43
|
|
|
return `${baseUrl()}/images/${imgFile}`; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Removes the base url or base pathname if the given url starts with them. |
|
48
|
|
|
* @param url |
|
49
|
|
|
*/ |
|
50
|
|
|
export function removeBaseUrl(url: string): string { |
|
51
|
|
|
const base = baseUrl(); |
|
52
|
|
|
if (url.startsWith(base)) { |
|
53
|
|
|
return url.substr(base.length); |
|
54
|
|
|
} |
|
55
|
|
|
const basePath = basePathname(); |
|
56
|
|
|
if (url.startsWith(basePath)) { |
|
57
|
|
|
return url.substr(basePath.length); |
|
58
|
|
|
} |
|
59
|
|
|
return url; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
export function jobShow(locale: string, jobId: number): string { |
|
63
|
|
|
return `${baseUrl()}/${locale}/jobs/${jobId}`; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
function applicationShow( |
|
67
|
|
|
locale: string, |
|
68
|
|
|
prefix: string, |
|
69
|
|
|
applicationId: number, |
|
70
|
|
|
jobId: number, |
|
71
|
|
|
): string { |
|
72
|
|
|
return `${baseUrl()}/${locale}/${prefix}/jobs/${jobId}/applications/${applicationId}`; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
function applicantShow( |
|
76
|
|
|
locale: string, |
|
77
|
|
|
prefix: string, |
|
78
|
|
|
applicantId: number, |
|
79
|
|
|
jobId: number, |
|
80
|
|
|
): string { |
|
81
|
|
|
return `${baseUrl()}/${locale}/${prefix}/jobs/${jobId}/applicants/${applicantId}`; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
export function managerApplicationShow( |
|
85
|
|
|
locale: string, |
|
86
|
|
|
applicationId: number, |
|
87
|
|
|
jobId: number, |
|
88
|
|
|
): string { |
|
89
|
|
|
return applicationShow(locale, "manager", applicationId, jobId); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
export function managerApplicantShow( |
|
93
|
|
|
locale: string, |
|
94
|
|
|
applicantId: number, |
|
95
|
|
|
jobId: number, |
|
96
|
|
|
): string { |
|
97
|
|
|
return applicantShow(locale, "manager", applicantId, jobId); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
export function managerEditProfile(locale: string): string { |
|
101
|
|
|
return `${baseUrl()}/${locale}/manager/profile`; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
export function managerJobIndex(locale: string): string { |
|
105
|
|
|
return `${baseUrl()}/${locale}/manager/jobs`; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
export function managerJobSummary(locale: string, jobId: number): string { |
|
109
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}`; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
export function managerJobPreview(locale: string, jobId: number): string { |
|
113
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/preview`; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
export function managerJobApplications(locale: string, jobId: number): string { |
|
117
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/applications`; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
export function managerScreeningPlan(locale: string, jobId: number): string { |
|
121
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/assessment-plan`; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
export function applicationReviewUpdate( |
|
125
|
|
|
locale: string, |
|
126
|
|
|
applicationId: number, |
|
127
|
|
|
): string { |
|
128
|
|
|
return `${baseApiUrl()}/applications/${applicationId}/review`; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
export function jobBuilderIntro(locale: string, jobId?: number): string { |
|
132
|
|
|
if (jobId) { |
|
133
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/intro`; |
|
134
|
|
|
} |
|
135
|
|
|
return `${baseUrl()}/${locale}/manager/job-builder/intro`; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
export function jobBuilderDetails(locale: string, jobId: number): string { |
|
139
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/details`; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
export function jobBuilderEnv(locale: string, jobId: number): string { |
|
143
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/environment`; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
export function jobBuilderImpact(locale: string, jobId: number): string { |
|
147
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/impact`; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
export function jobBuilderTasks(locale: string, jobId: number): string { |
|
151
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/tasks`; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
export function jobBuilderSkills(locale: string, jobId: number): string { |
|
155
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/skills`; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
export function jobBuilderReview(locale: string, jobId: number): string { |
|
159
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/review`; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
type FaqSection = "manager-who" | "levels"; |
|
163
|
|
|
|
|
164
|
|
|
export function applicantFaq(locale: string, faqSection?: FaqSection): string { |
|
165
|
|
|
const base = `${baseUrl()}/${locale}/faq`; |
|
166
|
|
|
if (faqSection) { |
|
167
|
|
|
return `${base}#${faqSection}`; |
|
168
|
|
|
} |
|
169
|
|
|
return base; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
export function managerFaq(locale: string, faqSection?: FaqSection): string { |
|
173
|
|
|
const base = `${baseUrl()}/${locale}/manager/faq`; |
|
174
|
|
|
if (faqSection) { |
|
175
|
|
|
return `${base}#${faqSection}`; |
|
176
|
|
|
} |
|
177
|
|
|
return base; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
export function hrJobIndex(locale: string): string { |
|
181
|
|
|
return `${baseUrl()}/${locale}/hr/jobs`; |
|
182
|
|
|
} |
|
183
|
|
|
export function hrJobSummary(locale: string, jobId: number): string { |
|
184
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}`; |
|
185
|
|
|
} |
|
186
|
|
|
export function hrJobReview(locale: string, jobId: number): string { |
|
187
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/review`; |
|
188
|
|
|
} |
|
189
|
|
|
export function hrJobPreview(locale: string, jobId: number): string { |
|
190
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/preview`; |
|
191
|
|
|
} |
|
192
|
|
|
export function hrScreeningPlan(locale: string, jobId: number): string { |
|
193
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/assessment-plan`; |
|
194
|
|
|
} |
|
195
|
|
|
export function hrJobApplications(locale: string, jobId: number): string { |
|
196
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/applications`; |
|
197
|
|
|
} |
|
198
|
|
|
export const hrApplicationShow = ( |
|
199
|
|
|
locale: string, |
|
200
|
|
|
applicationId: number, |
|
201
|
|
|
jobId: number, |
|
202
|
|
|
): string => applicationShow(locale, "hr", applicationId, jobId); |
|
203
|
|
|
export const hrApplicantShow = ( |
|
204
|
|
|
locale: string, |
|
205
|
|
|
applicantId: number, |
|
206
|
|
|
jobId: number, |
|
207
|
|
|
): string => applicantShow(locale, "hr", applicantId, jobId); |
|
208
|
|
|
|
|
209
|
|
|
export function accountSettings(locale: string): string { |
|
210
|
|
|
return `${baseUrl()}/${locale}/settings`; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
export function applicationIndex(locale: Locales): string { |
|
214
|
|
|
return `${baseUrl()}/${locale}/applications`; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
function baseApplicationUrl(locale: Locales, applicationId) { |
|
218
|
|
|
return `${baseUrl()}/${locale}/applications/${applicationId}`; |
|
219
|
|
|
} |
|
220
|
|
|
export function applicationWelcome( |
|
221
|
|
|
locale: Locales, |
|
222
|
|
|
applicationId: number, |
|
223
|
|
|
): string { |
|
224
|
|
|
return `${baseApplicationUrl(locale, applicationId)}/welcome`; |
|
225
|
|
|
} |
|
226
|
|
|
export function applicationBasic( |
|
227
|
|
|
locale: Locales, |
|
228
|
|
|
applicationId: number, |
|
229
|
|
|
): string { |
|
230
|
|
|
return `${baseApplicationUrl(locale, applicationId)}/basic`; |
|
231
|
|
|
} |
|
232
|
|
|
export function applicationExperienceIntro( |
|
233
|
|
|
locale: Locales, |
|
234
|
|
|
applicationId: number, |
|
235
|
|
|
): string { |
|
236
|
|
|
return `${baseApplicationUrl(locale, applicationId)}/experience-intro`; |
|
237
|
|
|
} |
|
238
|
|
|
export function applicationExperience( |
|
239
|
|
|
locale: Locales, |
|
240
|
|
|
applicationId: number, |
|
241
|
|
|
): string { |
|
242
|
|
|
return `${baseApplicationUrl(locale, applicationId)}/experience`; |
|
243
|
|
|
} |
|
244
|
|
|
export function applicationSkillsIntro( |
|
245
|
|
|
locale: Locales, |
|
246
|
|
|
applicationId: number, |
|
247
|
|
|
): string { |
|
248
|
|
|
return `${baseApplicationUrl(locale, applicationId)}/skills-intro`; |
|
249
|
|
|
} |
|
250
|
|
|
export function applicationSkills( |
|
251
|
|
|
locale: Locales, |
|
252
|
|
|
applicationId: number, |
|
253
|
|
|
): string { |
|
254
|
|
|
return `${baseApplicationUrl(locale, applicationId)}/skills`; |
|
255
|
|
|
} |
|
256
|
|
|
export function applicationFit(locale: Locales, applicationId: number): string { |
|
257
|
|
|
return `${baseApplicationUrl(locale, applicationId)}/fit`; |
|
258
|
|
|
} |
|
259
|
|
|
export function applicationReview( |
|
260
|
|
|
locale: Locales, |
|
261
|
|
|
applicationId: number, |
|
262
|
|
|
): string { |
|
263
|
|
|
return `${baseApplicationUrl(locale, applicationId)}/review`; |
|
264
|
|
|
} |
|
265
|
|
|
export function applicationSubmission( |
|
266
|
|
|
locale: Locales, |
|
267
|
|
|
applicationId: number, |
|
268
|
|
|
): string { |
|
269
|
|
|
return `${baseApplicationUrl(locale, applicationId)}/submission`; |
|
270
|
|
|
} |
|
271
|
|
|
export function applicationNextSteps( |
|
272
|
|
|
locale: Locales, |
|
273
|
|
|
applicationId: number, |
|
274
|
|
|
): string { |
|
275
|
|
|
return `${baseApplicationUrl(locale, applicationId)}/next`; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* Converts a string to a url safe equivalent. |
|
280
|
|
|
* @param string Any input text. |
|
281
|
|
|
* @returns url safe string. |
|
282
|
|
|
*/ |
|
283
|
|
|
export function slugify(string: string): string { |
|
284
|
|
|
const a = |
|
285
|
|
|
"àáâäæãåāăąçćčđďèéêëēėęěğǵḧîïíīįìłḿñńǹňôöòóœøōõőṕŕřßśšşșťțûüùúūǘůűųẃẍÿýžźż·/_,:;"; |
|
286
|
|
|
const b = |
|
287
|
|
|
"aaaaaaaaaacccddeeeeeeeegghiiiiiilmnnnnoooooooooprrsssssttuuuuuuuuuwxyyzzz------"; |
|
288
|
|
|
const p = new RegExp(a.split("").join("|"), "g"); |
|
289
|
|
|
|
|
290
|
|
|
return string |
|
291
|
|
|
.toString() |
|
292
|
|
|
.toLowerCase() |
|
293
|
|
|
.replace(/\s+/g, "-") // Replace spaces with - |
|
294
|
|
|
.replace(p, (c) => b.charAt(a.indexOf(c))) // Replace special characters |
|
295
|
|
|
.replace(/&/g, "-and-") // Replace & with 'and' |
|
296
|
|
|
.replace(/[^\w\-]+/g, "") // Remove all non-word characters |
|
297
|
|
|
.replace(/\-\-+/g, "-") // Replace multiple - with single - |
|
298
|
|
|
.replace(/^-+/, "") // Trim - from start of text |
|
299
|
|
|
.replace(/-+$/, ""); // Trim - from end of text |
|
300
|
|
|
} |
|
301
|
|
|
|