vanilli-shop-client
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -6,3 +6,3 @@ import RootApi from "./root-api"; | ||
private readonly endpoint; | ||
sendInquiry(inquiry: IEmailDto): Promise<AxiosResponse>; | ||
sendInquiry(inquiry: IEmailDto): Promise<AxiosResponse | undefined>; | ||
} |
@@ -67,12 +67,17 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var formData, name; | ||
var formData, email, msg, name_1; | ||
return __generator(this, function (_a) { | ||
formData = new FormData(); | ||
name = inquiry.name; | ||
if (name) { | ||
formData.append("Name", name); | ||
email = inquiry.email; | ||
msg = inquiry.msg; | ||
if (email && msg) { | ||
formData.append("Email", email); | ||
formData.append("Message", msg); | ||
name_1 = inquiry.name; | ||
if (name_1) { | ||
formData.append("Name", name_1); | ||
} | ||
return [2 /*return*/, this.makePostCall(this.endpoint, formData)]; | ||
} | ||
formData.append("Email", inquiry.email); | ||
formData.append("Message", inquiry.msg); | ||
return [2 /*return*/, this.makePostCall(this.endpoint, formData)]; | ||
return [2 /*return*/, undefined]; | ||
}); | ||
@@ -79,0 +84,0 @@ }); |
export interface IEmailDto { | ||
name?: string; | ||
email: string; | ||
msg: string; | ||
email: string | undefined; | ||
msg: string | undefined; | ||
} |
@@ -65,3 +65,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var notificationStore, result, data, e_1; | ||
var notificationStore, result, translationStore, data, e_1; | ||
return __generator(this, function (_a) { | ||
@@ -78,8 +78,14 @@ switch (_a.label) { | ||
result = _a.sent(); | ||
data = result.data; | ||
if (data.valid) { | ||
notificationStore.notifySuccess(this.translationStore.t("email.success", "Täname kirja eest! Võtame teiega peatselt ühendust!")); | ||
translationStore = this.translationStore; | ||
if (result) { | ||
data = result.data; | ||
if (data.valid) { | ||
notificationStore.notifySuccess(translationStore.t("email.success", "Täname kirja eest! Võtame teiega peatselt ühendust!")); | ||
} | ||
else { | ||
notificationStore.notifyErrors(data.errors); | ||
} | ||
} | ||
else { | ||
notificationStore.notifyErrors(data.errors); | ||
notificationStore.notifyError(translationStore.t("email.failure", "Kahjuks saatmine ebaõnnestus! Palun veenduge, et olete lisanud oma e-posti aadressi ja sõnumi sisu")); | ||
} | ||
@@ -86,0 +92,0 @@ return [3 /*break*/, 5]; |
{ | ||
"name": "vanilli-shop-client", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Client for Vanilli Shop API", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -8,14 +8,21 @@ import RootApi from "./root-api"; | ||
async sendInquiry(inquiry: IEmailDto): Promise<AxiosResponse> { | ||
async sendInquiry(inquiry: IEmailDto): Promise<AxiosResponse | undefined> { | ||
const formData = new FormData(); | ||
const name = inquiry.name; | ||
const email = inquiry.email; | ||
const msg = inquiry.msg; | ||
if (name) { | ||
formData.append("Name", name); | ||
if (email && msg) { | ||
formData.append("Email", email); | ||
formData.append("Message", msg); | ||
const name = inquiry.name; | ||
if (name) { | ||
formData.append("Name", name); | ||
} | ||
return this.makePostCall(this.endpoint, formData); | ||
} | ||
formData.append("Email", inquiry.email); | ||
formData.append("Message", inquiry.msg); | ||
return this.makePostCall(this.endpoint, formData); | ||
return undefined; | ||
} | ||
} |
export interface IEmailDto { | ||
name?: string, | ||
email: string, | ||
msg: string | ||
email: string | undefined, | ||
msg: string | undefined | ||
} |
@@ -11,8 +11,14 @@ import BaseStore from "./base-store"; | ||
const result = await this.rootStore.emailApi.sendInquiry(inquiry); | ||
const data = result.data; | ||
const translationStore = this.translationStore; | ||
if (data.valid) { | ||
notificationStore.notifySuccess(this.translationStore.t("email.success", "Täname kirja eest! Võtame teiega peatselt ühendust!")); | ||
if (result) { | ||
const data = result.data; | ||
if (data.valid) { | ||
notificationStore.notifySuccess(translationStore.t("email.success", "Täname kirja eest! Võtame teiega peatselt ühendust!")); | ||
} else { | ||
notificationStore.notifyErrors(data.errors); | ||
} | ||
} else { | ||
notificationStore.notifyErrors(data.errors); | ||
notificationStore.notifyError(translationStore.t("email.failure", "Kahjuks saatmine ebaõnnestus! Palun veenduge, et olete lisanud oma e-posti aadressi ja sõnumi sisu")); | ||
} | ||
@@ -19,0 +25,0 @@ } catch (e) { |
163517
3711