Skip to content

Commit

Permalink
form data handle
Browse files Browse the repository at this point in the history
  • Loading branch information
tusheer committed Mar 2, 2022
1 parent 8fc838e commit 0594046
Show file tree
Hide file tree
Showing 13 changed files with 443 additions and 288 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions client/src/api/members/createMember.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { AxiosResponse } from 'axios';
import { http } from '../../../config';
import { IMember, MembershipType } from '../../types/Member';

interface ICreateMember {
firstName: string;
lastName: string;
email: string;
number: string;
file: File;
membershipType: MembershipType;
occupation: string;
}
interface ICreateResponse {
success: string;
message: string;
result: IMember;
}

const createMemberAction = async (body: ICreateMember) => {
const formData = new FormData();

Object.entries(body).forEach(([key, value]) => {
formData.append(key, value);
});

try {
const response = await http.post<typeof formData, AxiosResponse<ICreateResponse>>('/members', formData);
return response.data;
} catch (error) {
throw new Error();
}
};

export default createMemberAction;
4 changes: 2 additions & 2 deletions client/src/libs/useForm/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const useForm = <P>({ onSubmit, formState }: IuseFrom<P>): IUserFormReturn<P> =>
if (errorResolve.length) {
for (let i = 0; i < errorResolve.length; i++) {
const name = errorResolve[i];
const validate = validationRef.current[name]?.generateErrors(state[name]);
const validate = validationRef.current[name]?.getErrors(state[name]);
if (validate?.error) {
errors[name] = validate;
}
Expand Down Expand Up @@ -43,7 +43,7 @@ const useForm = <P>({ onSubmit, formState }: IuseFrom<P>): IUserFormReturn<P> =>
...state,
[name]: changeValue,
});
const getErros = validate?.generateErrors(changeValue);
const getErros = validate?.getErrors(changeValue);
if (getErros?.error) {
setErrors({
...errors,
Expand Down
8 changes: 6 additions & 2 deletions client/src/libs/useForm/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class Validator {
}
};

generateErrors = (value: unknown, digginValue?: Function) => {
private generateErrors = (value: unknown, digginValue?: Function) => {
const parseValue = digginValue ? digginValue(value) : value;
const resolve = this.errros.reduce(
(prevValue: { error: boolean; message: string[] }, current) => {
Expand All @@ -54,10 +54,14 @@ export class Validator {
return resolve;
};

getErrors = (value: any) => {
return this.generateErrors(value);
};

findKey = <T>(callback: (value: T) => string) => {
return {
...this,
get: (value: T) => this.generateErrors(value, callback),
getErrors: (value: T) => this.generateErrors(value, callback),
};
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,80 +1,101 @@
.root {
z-index: 20;
.input_wraper {
min-height: 50px;
box-shadow: 0 1px 0 0 #e8e8e8;
background-color: #fafafa;
.item_wraper {
font-size: 11px;
width: calc(100% - 40px);
display: flex;
gap: 5px;
}
.arrow_wrraper {
.arrow {
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid #bebebe;
}
}
}
z-index: 20;
.input_wraper {
min-height: 50px;
box-shadow: 0 1px 0 0 #e8e8e8;
background-color: #fafafa;
.item_wraper {
font-size: 11px;
width: calc(100% - 40px);
display: flex;
gap: 5px;
}
.arrow_wrraper {
.arrow {
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid #bebebe;
}
}
}
.error_text {
color: #ff5b43;
font-size: 11px;
font-weight: 500;
}

ul {
width: calc(100% - 40px);
top: calc(100% + 2px);
box-shadow: 5px 15px 20px 0 rgba(0, 0, 0, 0.1);
ul {
width: calc(100% - 40px);
top: calc(100% + 2px);
box-shadow: 5px 15px 20px 0 rgba(0, 0, 0, 0.1);

li {
width: 100%;
display: block;
padding: 9px;
font-size: 14px;
border-radius: 4px;
&:hover {
background: #f4f4f4;
// color: #63636a;
}
}
}
li {
width: 100%;
display: block;
padding: 9px;
font-size: 14px;
border-radius: 4px;
&:hover {
background: #f4f4f4;
// color: #63636a;
}
}
}

.error {
border-color: #ff5b43 !important;
}
.error {
border-color: #ff5b43 !important;
}

.error_text {
color: #ff5b43;
font-size: 11px;
font-weight: 500;
}
.error_text {
color: #ff5b43;
font-size: 11px;
font-weight: 500;
}

&:focus-within {
.input_wraper {
background-color: white;
border: 1px solid #01896a;
box-shadow: 0 1px 0 0 #01896a;
}
&:focus-within {
.input_wraper {
background-color: white;
border: 1px solid #9c51e0;
box-shadow: 0 1px 0 0 #9c51e0;
}

.span_label {
top: -22px;
left: 0;
font-size: 0.875rem;
color: #01896a;
}
}
.span_label_active {
top: -22px !important;
left: 0px !important;
}
.span_label {
top: -22px;
left: 0;
font-size: 0.875rem;
color: #9c51e0;
}
}
.span_label_active {
top: -22px !important;
left: 0px !important;
}

.span_label {
top: 16px;
left: 14px;
position: absolute;
font-size: 0.875rem;
font-weight: 500;
text-align: left;
color: #9797a0;
letter-spacing: 0.65px;
transition: all 0.15s ease-in-out 0s;
}
.span_label {
top: 16px;
left: 14px;
position: absolute;
font-size: 0.875rem;
font-weight: 500;
text-align: left;
color: #9797a0;
letter-spacing: 0.65px;
transition: all 0.15s ease-in-out 0s;
}
}

.error {
.input_wraper {
box-shadow: 0 1px 0 0 #ff5b43 !important;
}
&:focus-within {
.input_wraper {
border: 1px solid #ff5b43 !important;
box-shadow: 0 1px 0 0 #ff5b43 !important;
}

.span_label {
color: #ff5b43 !important;
}
}
}
Loading

0 comments on commit 0594046

Please sign in to comment.