Untitled

mail@pastecode.io avatar
unknown
javascript
3 years ago
1.0 kB
4
Indexable
export const validateOrg = createAsyncThunk(
	"auth/orgsignup",
	async (params = {}, ThunkAPI) => {
		try {
			ThunkAPI.dispatch(pageLoaded({ loading: true }));
			const data = new FormData();
			const { imageUrl } = params;
			if (imageUrl) {
				const file = dataURLtoFile(imageUrl, new Date().toDateString());
				data.append("template", file, file.name);
			}
			const {
				orgName,
				email,
				password,
				confirmPassword,
				domain,
				mobileNumber,
			} = params;
			data.append(
				"metadata",
				JSON.stringify({
					orgName,
					email,
					password,
					domain,
					confirmPassword,
					mobileNumber,
				})
			);

			const response = await axios.post(
				`${apiEndPoint}/api/auth/signup`,
				data,
				{
					headers: {
						"Content-Type": "multipart/form-data",
					},
				}
			);

			if (response) {
				return response.data;
			}
		} catch (err) {
			console.log("-=-=-=-=-=-err", err);
			console.log("-=-=-=-=-=-err.response.data", err.response);
			return ThunkAPI.rejectWithValue(err.response.data);
		}
	}
);