Skip to content

Commit c81381b

Browse files
committed
bug fix on job post when toggle remote
1 parent 683f513 commit c81381b

File tree

5 files changed

+44
-44
lines changed

5 files changed

+44
-44
lines changed

server/src/common/authentication/auth_keys_service.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ impl Authenticator for AuthService {
8383
if header_name.to_lowercase() == "authorization" {
8484
let bearer_items: Vec<&str> = header_val.split(' ').collect();
8585
let claims = decode_token(bearer_items.get(1).unwrap(), decoding_key);
86-
info!("claims {:?}", claims);
8786
info!("checking against user_name {}", user_name);
8887
if claims.sub == user_name {
8988
if claims.exp >= (Utc::now().timestamp() as usize) {

server/src/common/repository/jobs/repo.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@ use crate::common::repository::jobs::models::{NewJob, Job, UpdateJob, JobApplied
66
use crate::common::repository::base::EntityId;
77
use crate::common::repository::{error::SqlxError, developers::models::Developer, base::CountResult};
88
use log::error;
9-
109
use super::models::JobApplicant;
1110

1211
mod internal {
1312
use chrono::Utc;
14-
1513
use crate::common::repository::jobs::models::JobApplicant;
16-
1714
use super::*;
1815

1916
pub async fn insert_job(conn: &Pool<Postgres>, new_job: NewJob) -> Result<EntityId, Error> {
@@ -52,6 +49,7 @@ mod internal {
5249
let job_id = inserted_entity.unwrap().id;
5350
if new_job.is_remote {
5451
if let Some(_) = new_job.country_id {
52+
error!("insert job error: is_remote and country cannot both be given");
5553
return Err(sqlx::Error::Database(Box::new(SqlxError::IsRemoteContstraintError)));
5654
}
5755
} else {
@@ -74,9 +72,11 @@ mod internal {
7472
Err(e) => Err(e)
7573
};
7674
if let Err(e) = jobs_countries_result {
75+
error!("insert job error: {:?}", e);
7776
return Err(e);
7877
}
7978
} else {
79+
error!("insert job error: when is_remote is false country must be given");
8080
return Err(sqlx::Error::Database(Box::new(SqlxError::IsRemoteContstraintError)));
8181
}
8282
}
@@ -123,6 +123,7 @@ mod internal {
123123

124124
if update_job.is_remote {
125125
if let Some(_) = update_job.country_id {
126+
error!("update job error: is_remote and country cannot both be given");
126127
return Err(sqlx::Error::Database(Box::new(SqlxError::IsRemoteContstraintError)));
127128
} else {
128129
let delete_job_country_result = query::<_>(

server/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ use actix_web::{HttpServer, http::header, App, middleware::Logger, web};
115115
use common::authentication::auth_keys_service::{init_auth_keys, AuthService};
116116
use common::emailer::emailer::Emailer;
117117
use common::repository::base::{DbRepo, Repository};
118-
use log::info;
119118
use routes::application::routes::{create_application, developer_applied};
120119
use routes::authentication::routes::{login, refresh_access_token};
121120
use routes::developers::routes::{get_developer_by_email, update_developer};

webclient/src/presentation/components/controls/Checkbox.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ReactNode } from "react";
1+
import { ChangeEvent, ReactNode } from "react";
22
import "../../theme/checkbox.css";
33

44
interface CheckboxProps {
@@ -14,7 +14,8 @@ export default function Checkbox({
1414
children,
1515
name,
1616
}: CheckboxProps) {
17-
const onChange = () => {
17+
const onChange = (e: ChangeEvent<HTMLInputElement>) => {
18+
e.preventDefault();
1819
toggleIsChecked();
1920
};
2021

webclient/src/presentation/components/jobs/JobFullview.tsx

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
} from "../../../domain/repository/JobApplicationRepo";
3939
import { Popup } from "../controls/Popup";
4040
import { ValidationMsgView } from "../controls/ValidationMsgView";
41+
import EmpProfile from "../../models/EmpProfile";
4142

4243
type JobPostDisplayComponents = {
4344
title: JSX.Element;
@@ -200,10 +201,10 @@ export default function JobFullview({ userType }: JobFullviewProps) {
200201
updatedAt: formatDistanceToNow(new Date()),
201202
title: "",
202203
description: null,
203-
employerId: 1,
204+
employerId: profile ? Number(profile.id) : 0,
204205
employerName: "",
205206
isRemote: false,
206-
companyId: 1,
207+
companyId: profile ? Number((profile as EmpProfile).companyId) : 0,
207208
companyName: "",
208209
countryId: 1,
209210
countryName: "",
@@ -217,7 +218,7 @@ export default function JobFullview({ userType }: JobFullviewProps) {
217218
salary: "",
218219
companyLogo: undefined,
219220
});
220-
const [lastCountryId, setLastCountryId] = useState<number>();
221+
const [lastCountryId, setLastCountryId] = useState<number | undefined>(1);
221222
/// formValues used for form submission
222223
const formValues = useRef<JobFormState>({
223224
id: 0,
@@ -236,15 +237,13 @@ export default function JobFullview({ userType }: JobFullviewProps) {
236237
const [validationMessage, setValidationMessage] = useState("");
237238
const [successMessage, setSuccessMessage] = useState("");
238239

239-
useEffect(() => {
240-
console.log("popup state", isPopupOpen);
241-
}, []);
242-
243240
useEffect(() => {
244241
let currentJobPost: JobPost | undefined = undefined;
245242
if (routeJobPost) {
246243
currentJobPost = routeJobPost as JobPost;
247244
setJobPostStates(currentJobPost);
245+
} else {
246+
setJobPostStates(null);
248247
}
249248
}, [routeJobPost]);
250249

@@ -271,7 +270,6 @@ export default function JobFullview({ userType }: JobFullviewProps) {
271270
) {
272271
developerAppliedToJob(currentJobPost.id, Number(profile.id)).then(
273272
(disableApplyBtn) => {
274-
console.log("dev already applied?", disableApplyBtn);
275273
setSubmitDisabled(disableApplyBtn);
276274
}
277275
);
@@ -296,83 +294,86 @@ export default function JobFullview({ userType }: JobFullviewProps) {
296294
currentJobPost.description = markdown;
297295
};
298296

299-
const setJobPostStates = (jobPost: JobPost) => {
300-
setCurrentJobPost({ type: FormActionTypes.Id, payload: jobPost.id });
297+
const setJobPostStates = (jobPost: JobPost | null) => {
298+
setCurrentJobPost({ type: FormActionTypes.Id, payload: jobPost?.id || 0 });
301299
setCurrentJobPost({
302300
type: FormActionTypes.UpdatedAt,
303-
payload: jobPost.updatedAt,
301+
payload: jobPost?.updatedAt || formatDistanceToNow(new Date()),
302+
});
303+
setCurrentJobPost({
304+
type: FormActionTypes.Title,
305+
payload: jobPost?.title || "",
304306
});
305-
setCurrentJobPost({ type: FormActionTypes.Title, payload: jobPost.title });
306307
setCurrentJobPost({
307308
type: FormActionTypes.Desc,
308-
payload: jobPost.description,
309+
payload: jobPost?.description || null,
309310
});
310-
mdRef.current?.setMarkdown(jobPost.description);
311+
mdRef.current?.setMarkdown(jobPost?.description || "");
311312
setCurrentJobPost({
312313
type: FormActionTypes.EmployerId,
313-
payload: jobPost.employerId,
314+
payload: jobPost?.employerId || Number(profile!.id),
314315
});
315316
setCurrentJobPost({
316317
type: FormActionTypes.EmployerName,
317-
payload: jobPost.employerName,
318+
payload: jobPost?.employerName || "",
318319
});
319320
setCurrentJobPost({
320321
type: FormActionTypes.IsRemote,
321-
payload: jobPost.isRemote,
322+
payload: jobPost?.isRemote || false,
322323
});
323324
setCurrentJobPost({
324325
type: FormActionTypes.CompanyLogo,
325-
payload: jobPost.companyLogo,
326+
payload: jobPost?.companyLogo,
326327
});
327328
setCurrentJobPost({
328329
type: FormActionTypes.CompanyId,
329-
payload: jobPost.companyId,
330+
payload: jobPost?.companyId || 1,
330331
});
331332
setCurrentJobPost({
332333
type: FormActionTypes.CompanyName,
333-
payload: jobPost.companyName,
334+
payload: jobPost?.companyName || "",
334335
});
335336
setCurrentJobPost({
336337
type: FormActionTypes.CountryId,
337-
payload: jobPost.countryId,
338+
payload: jobPost?.countryId || 1,
338339
});
339340
// if no country selected just default to first on list, as there must be at least one
340-
setLastCountryId(jobPost.countryId || 1);
341+
setLastCountryId(jobPost?.countryId || 1);
341342
setCurrentJobPost({
342343
type: FormActionTypes.CountryName,
343-
payload: jobPost.countryName,
344+
payload: jobPost?.countryName || "",
344345
});
345346
setCurrentJobPost({
346347
type: FormActionTypes.PrimaryLangId,
347-
payload: jobPost.primaryLangId,
348+
payload: jobPost?.primaryLangId || 1,
348349
});
349350
setCurrentJobPost({
350351
type: FormActionTypes.PrimaryLangName,
351-
payload: jobPost.primaryLangName,
352+
payload: jobPost?.primaryLangName || "",
352353
});
353354
setCurrentJobPost({
354355
type: FormActionTypes.SecondaryLangId,
355-
payload: jobPost.secondaryLangId,
356+
payload: jobPost?.secondaryLangId || 1,
356357
});
357358
setCurrentJobPost({
358359
type: FormActionTypes.SecondaryLangName,
359-
payload: jobPost.secondaryLangName,
360+
payload: jobPost?.secondaryLangName || "",
360361
});
361362
setCurrentJobPost({
362363
type: FormActionTypes.IndustryId,
363-
payload: jobPost.industryId,
364+
payload: jobPost?.industryId || 1,
364365
});
365366
setCurrentJobPost({
366367
type: FormActionTypes.IndustryName,
367-
payload: jobPost.industryName,
368+
payload: jobPost?.industryName || "",
368369
});
369370
setCurrentJobPost({
370371
type: FormActionTypes.SalaryId,
371-
payload: jobPost.salaryId,
372+
payload: jobPost?.salaryId || 1,
372373
});
373374
setCurrentJobPost({
374375
type: FormActionTypes.Salary,
375-
payload: jobPost.salary,
376+
payload: jobPost?.salary || "",
376377
});
377378
};
378379

@@ -654,7 +655,6 @@ export default function JobFullview({ userType }: JobFullviewProps) {
654655

655656
const onJobSubmit = async (e: FormEvent<HTMLFormElement>) => {
656657
e.preventDefault();
657-
console.log("userType", userType);
658658
if (userType === UiDevOrEmployer.Developer) {
659659
await onJobApply();
660660
} else {
@@ -663,7 +663,6 @@ export default function JobFullview({ userType }: JobFullviewProps) {
663663
};
664664

665665
const onJobApply = async () => {
666-
console.log("apply job");
667666
// show login or register if not logged in
668667
if (!profile || !profile.accessToken) {
669668
setLoginOpen(!loginOpen);
@@ -691,8 +690,6 @@ export default function JobFullview({ userType }: JobFullviewProps) {
691690
};
692691

693692
const onJobSave = async () => {
694-
console.log("save job", currentJobPost.id);
695-
696693
try {
697694
setSubmitDisabled(true);
698695
setFormValues();
@@ -784,8 +781,11 @@ export default function JobFullview({ userType }: JobFullviewProps) {
784781
setValidationMessage("Country cannot be selected when Remote is checked");
785782
setSuccessMessage("");
786783
result = false;
784+
} else if (!formValues.current.isRemote && !formValues.current.countryId) {
785+
setValidationMessage("Country cannot be empty when not is remote");
786+
setSuccessMessage("");
787+
result = false;
787788
}
788-
console.log("validation result", result);
789789
return result;
790790
};
791791

@@ -891,7 +891,7 @@ export default function JobFullview({ userType }: JobFullviewProps) {
891891
name="save"
892892
disabled={submitDisabled}
893893
>
894-
save
894+
Save
895895
</button>
896896
)}
897897
</div>

0 commit comments

Comments
 (0)