Skip to content

Commit

Permalink
Merge pull request activist-org#916 from activist-org/org-create-via-…
Browse files Browse the repository at this point in the history
…store

Switch org creation to Pinia store + structure other stores + throttle increase
  • Loading branch information
andrewtavis authored Jun 30, 2024
2 parents 2072b64 + 591bd07 commit ded83cb
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 91 deletions.
4 changes: 2 additions & 2 deletions backend/tests/throttle.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class BaseTestThrottle:
__test__ = False
url = ""
client = APIClient()
anon_throttle = 7
user_throttle = 10
anon_throttle = 20
user_throttle = 30

@pytest.mark.django_db
@override_settings(
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/header/HeaderAppPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
>
<!-- organization.status === 1 means it's application is pending. -->
<h2
v-if="organization.id !== '' && organization.status === 1"
v-if="organization && organization.status === 1"
class="responsive-h4 text-light-warn-yellow transition-all duration-500 dark:text-dark-warn-yellow"
>
{{ $t("components.header-app-page.status-pending") }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</template>

<script setup lang="ts">
import type { OrganizationTextFormData } from "~/types/entities/organization";
import type { OrganizationUpdateTextFormData } from "~/types/entities/organization";
const props = defineProps<{
isOpen: boolean;
Expand All @@ -65,7 +65,7 @@ await organizationStore.fetchByID(id);
const { organization } = organizationStore;
const formData = ref<OrganizationTextFormData>({
const formData = ref<OrganizationUpdateTextFormData>({
description: "",
getInvolved: "",
getInvolvedURL: "",
Expand Down
56 changes: 10 additions & 46 deletions frontend/pages/organizations/create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,68 +116,32 @@
</template>

<script setup lang="ts">
import type { Organization } from "~/types/entities/organization";
import type { OrganizationCreateFormData } from "~/types/entities/organization";
definePageMeta({
middleware: ["user-only"],
});
const formData = ref({
const formData = ref<OrganizationCreateFormData>({
name: "",
tagline: "",
location: "",
description: "",
tagline: "",
social_accounts: [],
topics: [],
});
const token = localStorage.getItem("accessToken");
const localePath = useLocalePath();
const organizationStore = useOrganizationStore();
const submit = async () => {
const responseOrg = await useFetch(
`${BASE_BACKEND_URL}/entities/organizations/`,
{
method: "POST",
body: JSON.stringify({
name: formData.value.name,
location: formData.value.location,
tagline: formData.value.tagline,
social_accounts: ["https://twitter.com/activist-org"],
created_by: "cdfecc96-2dd5-435b-baba-a7610afee70e",
topics: ["test"],
high_risk: false,
total_flags: 0,
acceptance_date: new Date(),
}),
headers: {
Authorization: `Token ${token}`,
},
}
);
const responseOrgData = responseOrg.data.value as unknown as Organization;
const responseOrgText = await useFetch(
`${BASE_BACKEND_URL}/entities/organization_texts/`,
{
method: "POST",
body: JSON.stringify({
org_id: responseOrgData.id,
iso: 1,
description: formData.value.description,
get_involved: "",
donate_prompt: "",
}),
headers: {
Authorization: `Token ${token}`,
},
}
);
const responseID = await organizationStore.create(formData.value);
// TODO: Push notification with toast should be added here.
if (responseOrgText.error.value === null) {
navigateTo(localePath(`/organizations/${responseOrgData.id}`));
if (responseID) {
navigateTo(localePath(`/organizations/${responseID}`));
} else {
// TODO: Push notification with toast should be added here.
false;
}
};
</script>
24 changes: 18 additions & 6 deletions frontend/stores/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ export const useEventStore = defineStore("event", {
getInvolved: "",
}),
actions: {
async fetchByID(id: string | undefined) {
// MARK: API Calls
// MARK: Create

async create() {},

// MARK: Fetch By ID

async fetchByID(id: string | undefined) {
this.loading = true;

const [resEvent, resEventTexts] = await Promise.all([
Expand All @@ -59,8 +63,6 @@ export const useEventStore = defineStore("event", {
),
]);

// MARK: Result Parsing

const eventRes = resEvent.data as unknown as PiniaResEvent;
// const eventFAQRes = resEventFAQ.data as unknown as PiniaResEvent;
// const eventResourcesRes =
Expand All @@ -72,8 +74,6 @@ export const useEventStore = defineStore("event", {
// const resources = eventRes._value;
const texts = eventTextsRes._value.results[0];

// MARK: Assignment

this.id = event.id;
this.name = event.name;
this.tagline = event.tagline;
Expand All @@ -87,5 +87,17 @@ export const useEventStore = defineStore("event", {

this.loading = false;
},

// MARK: Fetch All

async fetchAll() {},

// MARK: Update

async update() {},

// MARK: Delete

async delete() {},
},
});
22 changes: 17 additions & 5 deletions frontend/stores/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ export const useGroupStore = defineStore("group", {
donationPrompt: "",
}),
actions: {
// MARK: Create

async create() {},

// MARK: Fetch By ID

async fetchByID(id: string | undefined) {
// MARK: API Calls
this.loading = true;

const [resGroup, resGroupOrg, resGroupTexts] = await Promise.all([
Expand Down Expand Up @@ -55,8 +60,6 @@ export const useGroupStore = defineStore("group", {
),
]);

// MARK: Result Parsing

const groupRes = resGroup.data as unknown as PiniaResGroup;
const groupOrgRes = resGroupOrg.data as unknown as PiniaResOrganization[];
// const groupFAQRes = resGroupFAQ.data as unknown as PiniaResGroup;
Expand All @@ -71,8 +74,6 @@ export const useGroupStore = defineStore("group", {
// const resources = groupRes._value;
const texts = groupTextsRes._value.results[0];

// MARK: Assignment

this.id = group.id;
this.name = group.name;
this.tagline = group.tagline;
Expand All @@ -87,6 +88,17 @@ export const useGroupStore = defineStore("group", {

this.loading = false;
},

// MARK: Fetch All

async fetchAll() {},

// MARK: Update

async update() {},

// MARK: Delete

async delete() {},
},
});
Loading

0 comments on commit ded83cb

Please sign in to comment.