Skip to content

Commit

Permalink
keep new value of pending changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Jan 29, 2024
1 parent a80980b commit c2c7aad
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 35 deletions.
3 changes: 1 addition & 2 deletions app/Http/Controllers/Dashboard/OrganizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ public function edit(): Response
'counties' => $this->getCounties(),
'changes' => Activity::pendingChangesFor($organization)
->get()
->flatMap(fn (Activity $activity) => $activity->properties->keys())
->flatMap(fn (Activity $activity) => $activity->properties)
->unique()
->values(),
]);
}

Expand Down
5 changes: 2 additions & 3 deletions app/Http/Controllers/Dashboard/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ public function edit(Project $project)
'projectCategories' => $this->getProjectCategories(),
'changes' => Activity::pendingChangesFor($project)
->get()
->flatMap(fn (Activity $activity) => $activity->properties->keys())
->unique()
->values(),
->flatMap(fn (Activity $activity) => $activity->properties)
->unique(),
]);
}

Expand Down
1 change: 1 addition & 0 deletions lang/ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@
"ticket_closed_at": "Închis la data",
"add_regional_project": "Adaugă un proiect regional",
"field_has_pending_changes": "Acest câmp are modificări neaprobare. Dacă il editezi, modificările vor fi pierdute.",
"field_pending_changes": "Noua valoare a campului este: ",
"verify_email_title": "Îți mulțumim că te-ai înregistrat pe platforma Bursa Binelui !",
"verify_email_description": "Te rugăm să îți validezi adresa de email pentru a-ți accesa contul. Dacă nu ai primit un email pentru validare, te rugăm să ne contactezi la [email protected].",
"verify_email_warning": "Dacă adresa de email nu va fi validată în 48 de ore, datele tale vor fi șterse și nu vor putea fi recuperate",
Expand Down
8 changes: 6 additions & 2 deletions resources/js/Components/Field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
<dd class="text-sm font-medium leading-6 text-gray-700 md:text-base md:col-span-6 2xl:col-span-7">
<slot name="value" />

<p v-show="hasPendingChanges" class="mt-2 text-sm text-red-600" v-text="$t('field_has_pending_changes')" />
<p v-show="hasPendingChanges" class="mt-2 text-sm text-red-600" v-text="$t('field_has_pending_changes')"/>
<p v-if="hasPendingChanges" class="mt-2 text-sm text-red-600">
{{ $t('field_pending_changes') }} {{ hasPendingChanges }}
</p>

<p v-show="hasErrors" class="mt-2 text-sm text-red-600" v-text="errors" />
</dd>

Expand All @@ -30,7 +34,7 @@
const props = defineProps({
label: String,
hasPendingChanges: {
type: Boolean,
type: String,
default: false,
},
alt: {
Expand Down
41 changes: 26 additions & 15 deletions resources/js/Pages/AdminOng/Organizations/Edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<FieldSection>
<!-- Edit organization name -->
<Field :label="$t('organization_name_label')" :hasPendingChanges="changes.includes('name')" alt>
<Field :label="$t('organization_name_label')" :hasPendingChanges="hasPendingChanges('name')" alt>
<template #value>
{{ organization.name }}
</template>
Expand All @@ -29,7 +29,7 @@
</Field>

<!-- Edit organization cif -->
<Field :label="$t('cif_label')" :hasPendingChanges="changes.includes('cif')">
<Field :label="$t('cif_label')" :hasPendingChanges="hasPendingChanges('cif')">
<template #value>
{{ organization.cif }}
</template>
Expand All @@ -54,7 +54,7 @@
</Field>

<!-- Edit organization image -->
<Field :label="$t('organization_logo_label')" :hasPendingChanges="changes.includes('logo')" alt>
<Field :label="$t('organization_logo_label')" :hasPendingChanges="hasPendingChanges('logo')" alt>
<template #value>
<img class="object-contain w-32 max-h-32 shrink-0" :src="organization.logo" alt="" />
</template>
Expand All @@ -73,7 +73,7 @@
</Field>

<!-- Edit organization description -->
<Field :label="$t('organization_description_label')" :hasPendingChanges="changes.includes('description')">
<Field :label="$t('organization_description_label')" :hasPendingChanges="hasPendingChanges('description')">
<template #value>
{{ organization.description }}
</template>
Expand All @@ -99,7 +99,7 @@
<!-- Edit activity domains -->
<Field
:label="$t('organization_activity_label')"
:hasPendingChanges="changes.includes('activity_domains')"
:hasPendingChanges="hasPendingChanges('activity_domains')"
alt
>
<template #value>
Expand All @@ -125,7 +125,7 @@
</Field>

<!-- Edit statute -->
<Field :label="$t('status_document_label')" :hasPendingChanges="changes.includes('statute')">
<Field :label="$t('status_document_label')" :hasPendingChanges="hasPendingChanges('statute')">
<template #value>
<a
v-if="organization.statute_link"
Expand All @@ -151,7 +151,7 @@
</Field>

<!-- Edit counties -->
<Field :label="$t('counties_label')" :hasPendingChanges="changes.includes('counties')" alt>
<Field :label="$t('counties_label')" :hasPendingChanges="hasPendingChanges('counties')" alt>
<template #value>
{{ organization.county_names.join(', ') }}
</template>
Expand Down Expand Up @@ -179,7 +179,7 @@
<!-- Edit accepts voluntiers -->
<Field
:label="$t('organization_accepts_volunteers')"
:hasPendingChanges="changes.includes('accepts_volunteers')"
:hasPendingChanges="hasPendingChanges('accepts_volunteers')"
alt
>
<template #value>
Expand Down Expand Up @@ -209,7 +209,7 @@
<!-- Edit why volunteer -->
<Field
:label="$t('organization_why_volunteer_label')"
:hasPendingChanges="changes.includes('why_volunteer')"
:hasPendingChanges="hasPendingChanges('why_volunteer')"
>
<template #value>
{{ organization.why_volunteer }}
Expand All @@ -236,7 +236,7 @@

<FieldSection :title="$t('organization_contact')">
<!-- Edit organizaton website -->
<Field :label="$t('organization_website_label')" :hasPendingChanges="changes.includes('website')" alt>
<Field :label="$t('organization_website_label')" :hasPendingChanges="hasPendingChanges('website')" alt>
<template #value>
<a
href="{{ organization.website }}"
Expand Down Expand Up @@ -267,7 +267,7 @@
</Field>

<!-- Edit organizaton email -->
<Field :label="$t('organization_email_label')" :hasPendingChanges="changes.includes('contact_email')">
<Field :label="$t('organization_email_label')" :hasPendingChanges="hasPendingChanges('contact_email')">
<template #value>
<a
href="mailto:{{ organization.contact_email }}"
Expand Down Expand Up @@ -298,7 +298,7 @@
</Field>

<!-- Edit organizaton phone -->
<Field :label="$t('organization_phone_label')" :hasPendingChanges="changes.includes('contact_phone')" alt>
<Field :label="$t('organization_phone_label')" :hasPendingChanges="hasPendingChanges('contact_phone')" alt>
<template #value>
{{ organization.contact_phone }}
</template>
Expand Down Expand Up @@ -326,7 +326,7 @@

<Field
:label="$t('organization_contact_person_label')"
:hasPendingChanges="changes.includes('contact_person')"
:hasPendingChanges="hasPendingChanges('contact_person')"
>
<template #value>
{{ organization.contact_person }}
Expand All @@ -352,7 +352,7 @@
</Field>

<!-- Edit organizaton address -->
<Field :label="$t('organization_address_street_address_label')" :hasPendingChanges="changes.includes('address')" alt>
<Field :label="$t('organization_address_street_address_label')" :hasPendingChanges="hasPendingChanges('address')" alt>
<template #value>
{{ organization.address }},
</template>
Expand Down Expand Up @@ -398,7 +398,7 @@
</template>

<script setup>
import { ref, computed } from 'vue';
import {ref, computed, onMounted} from 'vue';
import { router, useForm } from '@inertiajs/vue3';
import route from '@/Helpers/useRoute';
import Head from '@/Components/Head.vue';
Expand Down Expand Up @@ -434,6 +434,17 @@
});
};
const hasPendingChanges = (field) => {
let tmpChanges = props.changes;
if (Object.keys(tmpChanges).includes(field))
{
return tmpChanges[field].new;
}
return false;
};
const editField = (field) => {
const form = useForm({
[field]: props.organization[field],
Expand Down
35 changes: 22 additions & 13 deletions resources/js/Pages/AdminOng/Projects/EditProject.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<dl class="mt-6 border-t border-gray-100 divide-y divide-gray-100">
<Field
:label="$t('project_name_label')"
:hasPendingChanges="changes.includes('name')"
:hasPendingChanges="hasPendingChanges('name')"
:errors="formChangeStatus.errors.name"
>
<template #value>
Expand Down Expand Up @@ -40,7 +40,7 @@

<Field
:label="$t('amount_target_label')"
:hasPendingChanges="changes.includes('target_budget')"
:hasPendingChanges="hasPendingChanges('target_budget')"
:errors="formChangeStatus.errors.target_budget"
alt
>
Expand Down Expand Up @@ -69,7 +69,7 @@

<Field
:label="$t('period_start_donation')"
:hasPendingChanges="changes.includes('start')"
:hasPendingChanges="hasPendingChanges('start')"
:errors="formChangeStatus.errors.start"
>
<template #value> {{ project.start }} </template>
Expand Down Expand Up @@ -97,7 +97,7 @@

<Field
:label="$t('period_end_donation')"
:hasPendingChanges="changes.includes('end')"
:hasPendingChanges="hasPendingChanges('end')"
:errors="formChangeStatus.errors.end"
alt
>
Expand Down Expand Up @@ -126,7 +126,7 @@

<Field
:label="$t('project_category_label')"
:hasPendingChanges="changes.includes('categories')"
:hasPendingChanges="hasPendingChanges('categories')"
:errors="formChangeStatus.errors.categories"
>
<template #value>
Expand All @@ -152,7 +152,7 @@

<Field
:label="$t('counties_label')"
:hasPendingChanges="changes.includes('counties')"
:hasPendingChanges="hasPendingChanges('counties')"
:errors="formChangeStatus.errors.counties"
alt
>
Expand All @@ -179,7 +179,7 @@
</Field>
<Field
:label="$t('is_national')"
:hasPendingChanges="changes.includes('is_national')"
:hasPendingChanges="hasPendingChanges('is_national')"
:errors="formChangeStatus.errors.is_national"
alt
>
Expand Down Expand Up @@ -223,7 +223,7 @@

<Field
:label="$t('project_description_label')"
:hasPendingChanges="changes.includes('description')"
:hasPendingChanges="hasPendingChanges('description')"
:errors="formChangeStatus.errors.description"
>
<template #value>
Expand Down Expand Up @@ -254,7 +254,7 @@

<Field
:label="$t('project_scope_label')"
:hasPendingChanges="changes.includes('scope')"
:hasPendingChanges="hasPendingChanges('scope')"
:errors="formChangeStatus.errors.scope"
alt
>
Expand Down Expand Up @@ -284,7 +284,7 @@

<Field
:label="$t('project_beneficiary_label')"
:hasPendingChanges="changes.includes('beneficiaries')"
:hasPendingChanges="hasPendingChanges('beneficiaries')"
:errors="formChangeStatus.errors.beneficiaries"
>
<template #value>
Expand Down Expand Up @@ -318,7 +318,7 @@

<Field
:label="$t('why_to_donate')"
:hasPendingChanges="changes.includes('reason_to_donate')"
:hasPendingChanges="hasPendingChanges('reason_to_donate')"
:errors="formChangeStatus.errors.reason_to_donate"
alt
>
Expand Down Expand Up @@ -348,7 +348,7 @@

<Field
:label="$t('accepting_volunteers')"
:hasPendingChanges="changes.includes('accepting_volunteers')"
:hasPendingChanges="hasPendingChanges('accepting_volunteers')"
:errors="formChangeStatus.errors.accepting_volunteers"
>
<template #value>
Expand Down Expand Up @@ -391,7 +391,7 @@

<Field
:label="$t('accepting_comments')"
:hasPendingChanges="changes.includes('accepting_comments')"
:hasPendingChanges="hasPendingChanges('accepting_comments')"
:errors="formChangeStatus.errors.accepting_comments"
alt
>
Expand Down Expand Up @@ -607,6 +607,15 @@
id: project.value.id,
});
const hasPendingChanges = (field) => {
let tmpChanges = props.changes;
if (Object.keys(tmpChanges).includes(field))
{
return tmpChanges[field].new;
}
return false;
};
const changeProjectStatus = (id, status, type) => {
let tmpRoute =
type === 'regional' ? route('dashboard.projects.regional.status', id) : route('dashboard.projects.status', id);
Expand Down

0 comments on commit c2c7aad

Please sign in to comment.