Skip to content

Commit 3f6426f

Browse files
authoredFeb 17, 2024··
promotion: preprod to prod
feat: list form and delete form
2 parents 17afa93 + eee4a08 commit 3f6426f

23 files changed

+540
-47
lines changed
 

‎src/assets/images/empy_list.png

31.9 KB
Loading

‎src/gen/client/api.ts

+137-4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ export interface CreateForm {
8787
* @memberof CreateForm
8888
*/
8989
createdAt?: string;
90+
/**
91+
*
92+
* @type {string}
93+
* @memberof CreateForm
94+
*/
95+
updatedAt?: string;
9096
/**
9197
*
9298
* @type {boolean}
@@ -173,6 +179,12 @@ export interface Form {
173179
* @memberof Form
174180
*/
175181
createdAt?: string;
182+
/**
183+
*
184+
* @type {string}
185+
* @memberof Form
186+
*/
187+
updatedAt?: string;
176188
/**
177189
*
178190
* @type {boolean}
@@ -440,6 +452,56 @@ export const FormsApiAxiosParamCreator = function (
440452
options: localVarRequestOptions,
441453
};
442454
},
455+
/**
456+
*
457+
* @summary Delete one form using id
458+
* @param {string} formId Id the form
459+
* @param {*} [options] Override http request option.
460+
* @throws {RequiredError}
461+
*/
462+
deleteFormById: async (
463+
formId: string,
464+
options: RawAxiosRequestConfig = {}
465+
): Promise<RequestArgs> => {
466+
// verify required parameter 'formId' is not null or undefined
467+
assertParamExists("deleteFormById", "formId", formId);
468+
const localVarPath = `/forms/{formId}`.replace(
469+
`{${"formId"}}`,
470+
encodeURIComponent(String(formId))
471+
);
472+
// use dummy base URL string because the URL constructor only accepts absolute URLs.
473+
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
474+
let baseOptions;
475+
if (configuration) {
476+
baseOptions = configuration.baseOptions;
477+
}
478+
479+
const localVarRequestOptions = {
480+
method: "DELETE",
481+
...baseOptions,
482+
...options,
483+
};
484+
const localVarHeaderParameter = {} as any;
485+
const localVarQueryParameter = {} as any;
486+
487+
// authentication BearerAuth required
488+
// http bearer authentication required
489+
await setBearerAuthToObject(localVarHeaderParameter, configuration);
490+
491+
setSearchParams(localVarUrlObj, localVarQueryParameter);
492+
let headersFromBaseOptions =
493+
baseOptions && baseOptions.headers ? baseOptions.headers : {};
494+
localVarRequestOptions.headers = {
495+
...localVarHeaderParameter,
496+
...headersFromBaseOptions,
497+
...options.headers,
498+
};
499+
500+
return {
501+
url: toPathString(localVarUrlObj),
502+
options: localVarRequestOptions,
503+
};
504+
},
443505
/**
444506
*
445507
* @summary Get one form using id
@@ -493,11 +555,13 @@ export const FormsApiAxiosParamCreator = function (
493555
/**
494556
*
495557
* @summary Get own forms
558+
* @param {string} [sort]
496559
* @param {Form} [form]
497560
* @param {*} [options] Override http request option.
498561
* @throws {RequiredError}
499562
*/
500563
getOwnForms: async (
564+
sort?: string,
501565
form?: Form,
502566
options: RawAxiosRequestConfig = {}
503567
): Promise<RequestArgs> => {
@@ -521,6 +585,10 @@ export const FormsApiAxiosParamCreator = function (
521585
// http bearer authentication required
522586
await setBearerAuthToObject(localVarHeaderParameter, configuration);
523587

588+
if (sort !== undefined) {
589+
localVarQueryParameter["sort"] = sort;
590+
}
591+
524592
localVarHeaderParameter["Content-Type"] = "application/json";
525593

526594
setSearchParams(localVarUrlObj, localVarQueryParameter);
@@ -616,6 +684,36 @@ export const FormsApiFp = function (configuration?: Configuration) {
616684
configuration
617685
)(axios, localVarOperationServerBasePath || basePath);
618686
},
687+
/**
688+
*
689+
* @summary Delete one form using id
690+
* @param {string} formId Id the form
691+
* @param {*} [options] Override http request option.
692+
* @throws {RequiredError}
693+
*/
694+
async deleteFormById(
695+
formId: string,
696+
options?: RawAxiosRequestConfig
697+
): Promise<
698+
(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Form>
699+
> {
700+
const localVarAxiosArgs = await localVarAxiosParamCreator.deleteFormById(
701+
formId,
702+
options
703+
);
704+
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
705+
const localVarOperationServerBasePath =
706+
operationServerMap["FormsApi.deleteFormById"]?.[
707+
localVarOperationServerIndex
708+
]?.url;
709+
return (axios, basePath) =>
710+
createRequestFunction(
711+
localVarAxiosArgs,
712+
globalAxios,
713+
BASE_PATH,
714+
configuration
715+
)(axios, localVarOperationServerBasePath || basePath);
716+
},
619717
/**
620718
*
621719
* @summary Get one form using id
@@ -649,17 +747,20 @@ export const FormsApiFp = function (configuration?: Configuration) {
649747
/**
650748
*
651749
* @summary Get own forms
750+
* @param {string} [sort]
652751
* @param {Form} [form]
653752
* @param {*} [options] Override http request option.
654753
* @throws {RequiredError}
655754
*/
656755
async getOwnForms(
756+
sort?: string,
657757
form?: Form,
658758
options?: RawAxiosRequestConfig
659759
): Promise<
660760
(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Form>
661761
> {
662762
const localVarAxiosArgs = await localVarAxiosParamCreator.getOwnForms(
763+
sort,
663764
form,
664765
options
665766
);
@@ -719,6 +820,18 @@ export const FormsApiFactory = function (
719820
.crupdateFormQuestions(formId, question, options)
720821
.then((request) => request(axios, basePath));
721822
},
823+
/**
824+
*
825+
* @summary Delete one form using id
826+
* @param {string} formId Id the form
827+
* @param {*} [options] Override http request option.
828+
* @throws {RequiredError}
829+
*/
830+
deleteFormById(formId: string, options?: any): AxiosPromise<Form> {
831+
return localVarFp
832+
.deleteFormById(formId, options)
833+
.then((request) => request(axios, basePath));
834+
},
722835
/**
723836
*
724837
* @summary Get one form using id
@@ -734,13 +847,14 @@ export const FormsApiFactory = function (
734847
/**
735848
*
736849
* @summary Get own forms
850+
* @param {string} [sort]
737851
* @param {Form} [form]
738852
* @param {*} [options] Override http request option.
739853
* @throws {RequiredError}
740854
*/
741-
getOwnForms(form?: Form, options?: any): AxiosPromise<Form> {
855+
getOwnForms(sort?: string, form?: Form, options?: any): AxiosPromise<Form> {
742856
return localVarFp
743-
.getOwnForms(form, options)
857+
.getOwnForms(sort, form, options)
744858
.then((request) => request(axios, basePath));
745859
},
746860
};
@@ -789,6 +903,20 @@ export class FormsApi extends BaseAPI {
789903
.then((request) => request(this.axios, this.basePath));
790904
}
791905

906+
/**
907+
*
908+
* @summary Delete one form using id
909+
* @param {string} formId Id the form
910+
* @param {*} [options] Override http request option.
911+
* @throws {RequiredError}
912+
* @memberof FormsApi
913+
*/
914+
public deleteFormById(formId: string, options?: RawAxiosRequestConfig) {
915+
return FormsApiFp(this.configuration)
916+
.deleteFormById(formId, options)
917+
.then((request) => request(this.axios, this.basePath));
918+
}
919+
792920
/**
793921
*
794922
* @summary Get one form using id
@@ -806,14 +934,19 @@ export class FormsApi extends BaseAPI {
806934
/**
807935
*
808936
* @summary Get own forms
937+
* @param {string} [sort]
809938
* @param {Form} [form]
810939
* @param {*} [options] Override http request option.
811940
* @throws {RequiredError}
812941
* @memberof FormsApi
813942
*/
814-
public getOwnForms(form?: Form, options?: RawAxiosRequestConfig) {
943+
public getOwnForms(
944+
sort?: string,
945+
form?: Form,
946+
options?: RawAxiosRequestConfig
947+
) {
815948
return FormsApiFp(this.configuration)
816-
.getOwnForms(form, options)
949+
.getOwnForms(sort, form, options)
817950
.then((request) => request(this.axios, this.basePath));
818951
}
819952
}

‎src/index.css

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
@tailwind utilities;
55

66
@layer components {
7+
.list-view-header {
8+
@apply text-[14px] font-normal text-bgray text-start;
9+
}
10+
11+
.list-view-item {
12+
@apply text-[14px] my-3 font-normal text-bgray text-start bg-white rounded w-full flex items-center py-2;
13+
}
14+
715
.section {
816
@apply min-h-screen bg-[#f7f7fa] w-full;
917
}
@@ -24,10 +32,10 @@
2432
}
2533

2634
.form-block {
27-
@apply w-full rounded-[15px] shadow-gray-50 bg-white p-5 mb-7;
35+
@apply w-full rounded-[5px] shadow-gray-50 bg-white p-5 mb-7;
2836
}
2937

3038
.form-input {
31-
@apply placeholder:text-gray-700;
39+
@apply placeholder:text-gray-500;
3240
}
3341
}

‎src/operations/forms/FormList.jsx

-25
This file was deleted.

‎src/operations/forms/create/FormCreateModal.jsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { DEFAULT_FORM_VALUE } from "../../../stores/useCreateFormStore";
1515
import { useNotify } from "../../../hooks";
1616
import { formsProvider } from "../../../providers/formsProvider";
1717
import { useDashboardState } from "../../../stores";
18+
import { dumbLoading } from "../../utils";
1819

1920
export function FormCreateModal() {
2021
const [showCreate, setShowCreate] = useState(false);
@@ -33,6 +34,7 @@ export function FormCreateModal() {
3334
id: formId,
3435
title: title,
3536
createdAt: new Date().toISOString(),
37+
updatedAt: new Date().toISOString(),
3638
};
3739

3840
formsProvider
@@ -43,7 +45,7 @@ export function FormCreateModal() {
4345
color: "red",
4446
})
4547
)
46-
.finally(() => setIsLoading(false));
48+
.finally(() => dumbLoading(() => setIsLoading(false)));
4749
};
4850

4951
const closeModal = () => setShowCreate(false);

‎src/operations/forms/create/FormEdit.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useNavigate, useParams } from "react-router-dom";
66
import { formsProvider } from "../../../providers/formsProvider";
77
import { useCreateFormStore, useDashboardState } from "../../../stores";
88
import { useNotify } from "../../../hooks";
9+
import { dumbLoading } from "../../utils";
910

1011
export function FormEdit() {
1112
const params = useParams();
@@ -32,7 +33,7 @@ export function FormEdit() {
3233
});
3334
navigate("/dashboard");
3435
})
35-
.finally(() => setIsLoading(false));
36+
.finally(() => dumbLoading(() => setIsLoading(false)));
3637
};
3738
getFormById();
3839
}, [formId]);

‎src/operations/forms/create/components/CreateFormBody.jsx

+9-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Question } from "./Question";
66
import { useCreateFormStore, useDashboardState } from "../../../../stores";
77
import { formsProvider } from "../../../../providers/formsProvider";
88
import { useNotify } from "../../../../hooks";
9+
import { dumbLoading } from "../../../utils";
910

1011
// to avoid multiple rendering
1112
function SaveButton() {
@@ -19,13 +20,13 @@ function SaveButton() {
1920
}));
2021

2122
const saveForm = async () => {
22-
if (questions.length <= 0) {
23-
notify("Must add at least one question", { color: "red" });
24-
return;
25-
}
26-
2723
setIsLoading(true);
2824
const updateQuestions = async () => {
25+
if (questions.length <= 0) {
26+
dumbLoading(() => setIsLoading(false));
27+
navigate("/dashboard");
28+
}
29+
2930
formsProvider
3031
.setFormQuestions(formId, questions)
3132
.then(() => {
@@ -37,18 +38,18 @@ function SaveButton() {
3738
});
3839
})
3940
.finally(() => {
40-
setIsLoading(false);
41+
dumbLoading(() => setIsLoading(false));
4142
});
4243
};
4344

4445
formsProvider
45-
.crupdateForm(config)
46+
.crupdateForm({ ...config, updatedAt: new Date().toISOString() })
4647
.then(async () => updateQuestions())
4748
.catch(() => {
4849
notify("Oops, cannot update the forms, please try again", {
4950
color: "red",
5051
});
51-
setIsLoading(false);
52+
dumbLoading(() => setIsLoading(false));
5253
});
5354
};
5455

‎src/operations/forms/create/components/CreateFormHeader.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export function CreateFormHeader() {
5151
<CollapseConfig title="More configuration">
5252
<Switch
5353
label="Private"
54+
name="isPrivate"
5455
className="text-bgray text-[14px]"
5556
checked={config.isPrivate}
5657
onChange={({ target }) => updateConfig("isPrivate", target.checked)}

0 commit comments

Comments
 (0)
Please sign in to comment.