Skip to content

Commit

Permalink
feat: large refactor to commonize axios client
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriansaliou committed Nov 10, 2024
1 parent cafc5d4 commit 148b771
Show file tree
Hide file tree
Showing 21 changed files with 230 additions and 431 deletions.
6 changes: 5 additions & 1 deletion config/development.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"environment": "development"
"environment": "development",

"api": {
"endpoint": "http://127.0.0.1:8000/v1/"
}
}
6 changes: 5 additions & 1 deletion config/production.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"environment": "production"
"environment": "production",

"api": {
"endpoint": "/api/v1/"
}
}
44 changes: 44 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* This file is part of prose-pod-dashboard
*
* Copyright 2024, Prose Foundation
*/

/**************************************************************************
* IMPORTS
* ************************************************************************* */

// NPM
import { default as axios, AxiosInstance } from "axios";

// PROJECT: COMMONS
import CONFIG from "@/commons/config";

/**************************************************************************
* STORE
* ************************************************************************* */

class API {
public readonly client: AxiosInstance;

constructor() {
// Initialize API HTTP client
this.client = this.__createClient();
}

private __createClient(): AxiosInstance {
return axios.create({
baseURL: CONFIG.api.endpoint,

headers: {
"Content-Type": "application/json"
}
});
}
}

/**************************************************************************
* EXPORTS
* ************************************************************************* */

export default new API();
52 changes: 0 additions & 52 deletions src/api/login.ts

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import axios from "axios";

const NETWORK_CHECK_URL = "/network/checks"; //// EFFACER ??

Check warning on line 14 in src/api/providers/advancedNetwork.ts

View workflow job for this annotation

GitHub Actions / test

'NETWORK_CHECK_URL' is assigned a value but never used

class AdvancedNetwork {
class APIAdvancedNetwork {
/** SERVER **/

/** NETWORK **/
Expand All @@ -26,4 +26,4 @@ class AdvancedNetwork {
}
}

export default new AdvancedNetwork();
export default new APIAdvancedNetwork();
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import axios from "axios";

export class AdvancedSecurity {
export class APIAdvancedSecurity {
/** CONFIG **/

async getWorkspaceConfig(): Promise<void> {
Expand Down Expand Up @@ -58,4 +58,4 @@ export class AdvancedSecurity {
}
}

export default new CustomizationWorkspace();
export default new APIAdvancedSecurity();
4 changes: 2 additions & 2 deletions src/api/connect.ts → src/api/providers/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import axios from "axios";

class Connect {
class APIConnect {
/** CONFIG **/

async initializeAccount(): Promise<void> {
Expand Down Expand Up @@ -39,4 +39,4 @@ class Connect {
}
}

export default new Connect();
export default new APIConnect();
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import axios from "axios";

const REACTIONS_URL = "/workspace/reactions";

class CustomizationReactions {
class APICustomizationReactions {
/** REACTIONS **/

async getAllReactions(): Promise<void> {
Expand Down Expand Up @@ -46,4 +46,4 @@ class CustomizationReactions {
}
}

export default new CustomizationReactions();
export default new APICustomizationReactions();
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import axios from "axios";

export class CustomizationWorkspace {
export class APICustomizationWorkspace {
/** CONFIG **/

async getWorkspaceConfig(): Promise<void> {
Expand Down Expand Up @@ -58,4 +58,4 @@ export class CustomizationWorkspace {
}
}

export default new CustomizationWorkspace();
export default new APICustomizationWorkspace();
4 changes: 2 additions & 2 deletions src/api/global.ts → src/api/providers/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import axios from "axios";

class Global {
class APIGlobal {
/** CONFIG **/

async getServerConfig(): Promise<void> {
Expand All @@ -18,4 +18,4 @@ class Global {
}
}

export default new Global();
export default new APIGlobal();
47 changes: 47 additions & 0 deletions src/api/providers/login.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* This file is part of prose-pod-dashboard
*
* Copyright 2024, Prose Foundation
*/

/**************************************************************************
* IMPORTS
* ************************************************************************* */

// PROJECT: API
import Api from "@/api";

/**************************************************************************
* INTERFACES
* ************************************************************************* */

interface LoginResponse {
token: string;
}

/**************************************************************************
* API
* ************************************************************************* */

class APILogin {
async login(username: string, password: string): Promise<LoginResponse> {
return (
await Api.client.post<LoginResponse>(
"/login",
{},
{
auth: {
username,
password
}
}
)
).data;
}
}

/**************************************************************************
* EXPORTS
* ************************************************************************* */

export default new APILogin();
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import axios from "axios";

const CONFIG_URL = "/server/config";

class ServerConfiguration {
class APIServerConfiguration {
/** MESSAGING **/

async resetMessagesConfig(): Promise<void> {
Expand Down Expand Up @@ -63,4 +63,4 @@ class ServerConfiguration {
}
}

export default new ServerConfiguration();
export default new APIServerConfiguration();
4 changes: 2 additions & 2 deletions src/api/teamMembers.ts → src/api/providers/teamMembers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import axios from "axios";

class TeamMembers {
class APITeamMembers {
/** INVITATIONS **/

async getAllInvitations(): Promise<void> {
Expand Down Expand Up @@ -53,4 +53,4 @@ class TeamMembers {
}
}

export default new TeamMembers();
export default new APITeamMembers();
21 changes: 4 additions & 17 deletions src/assemblies/start/StartLoginForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class="a-start-login-form__field"
type="email"
name="jid"
placeholder="Enter your Prose address…"
placeholder="Enter your Prose admin address…"
size="ultra-large"
autofocus
)
Expand Down Expand Up @@ -66,15 +66,11 @@

<script lang="ts">
// PROJECT: COMPONENTS
import BaseAlert from "@/components/base/BaseAlert.vue";
import BaseButton from "@/components/base/BaseButton.vue";
import BaseProseLogo from "@/components/base/BaseProseLogo.vue";
import FormCheckbox from "@/components/form/FormCheckbox.vue";
import FormField from "@/components/form/FormField.vue";
// PROJECT: STORES
// import Store from "@/store";
// INTERFACES
export interface StateForm {
jid: string;
Expand Down Expand Up @@ -111,22 +107,13 @@ export default {
};
},
created() {
// Populate initial values
// this.form.jid = Store.$account.last.jid || "";
},
methods: {
// --> EVENT LISTENERS <--
onSubmit(): void {
BaseAlert.error(
"Account credentials are invalid",
"Please check your password and try again"
);
// this.$emit("submit", {
// ...this.form
// });
this.$emit("submit", {
...this.form
});
}
}
};
Expand Down
Loading

0 comments on commit 148b771

Please sign in to comment.