subscription_model -> subscription
This commit is contained in:
2
frontend/src/app.d.ts
vendored
2
frontend/src/app.d.ts
vendored
@@ -17,7 +17,7 @@ interface Membership {
|
|||||||
start_date: string | '';
|
start_date: string | '';
|
||||||
end_date: string | '';
|
end_date: string | '';
|
||||||
parent_member_id: number | -1;
|
parent_member_id: number | -1;
|
||||||
subscription_model: Subscription;
|
subscription: Subscription;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BankAccount {
|
interface BankAccount {
|
||||||
|
|||||||
@@ -11,12 +11,14 @@
|
|||||||
/** @type {import('../../routes/auth/about/[id]/$types').ActionData} */
|
/** @type {import('../../routes/auth/about/[id]/$types').ActionData} */
|
||||||
export let form;
|
export let form;
|
||||||
|
|
||||||
/** @type {App.Locals['subscriptions']}*/
|
/** @type {App.Locals['subscriptions'] | null}*/
|
||||||
export let subscriptions;
|
export let subscriptions;
|
||||||
|
|
||||||
/** @type {App.Locals['user']} */
|
/** @type {App.Locals['user']} */
|
||||||
export let user;
|
export let user;
|
||||||
|
|
||||||
|
export let submit_form = true;
|
||||||
|
|
||||||
// Ensure licence is initialized before passing to child
|
// Ensure licence is initialized before passing to child
|
||||||
$: if (user && !user.licence) {
|
$: if (user && !user.licence) {
|
||||||
user.licence = defaultLicence();
|
user.licence = defaultLicence();
|
||||||
@@ -30,7 +32,7 @@
|
|||||||
// $: isNewUser = user === null;
|
// $: isNewUser = user === null;
|
||||||
$: isLoading = user === undefined;
|
$: isLoading = user === undefined;
|
||||||
|
|
||||||
/** @type {App.Locals['licence_categories']} */
|
/** @type {App.Locals['licence_categories'] | null} */
|
||||||
export let licence_categories;
|
export let licence_categories;
|
||||||
|
|
||||||
const userStatusOptions = [
|
const userStatusOptions = [
|
||||||
@@ -60,9 +62,13 @@
|
|||||||
];
|
];
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
const TABS = hasPrivilige(user, PERMISSIONS.Member)
|
const TABS = [
|
||||||
? ['profile', 'licence', 'membership', 'bankaccount']
|
'profile',
|
||||||
: ['profile', 'bankaccount', 'membership'];
|
'bankaccount',
|
||||||
|
...(hasPrivilige(user, PERMISSIONS.Member) ? 'membership' : []),
|
||||||
|
...(user.licence ? 'licence' : [])
|
||||||
|
];
|
||||||
|
|
||||||
let activeTab = TABS[0];
|
let activeTab = TABS[0];
|
||||||
|
|
||||||
let isUpdating = false,
|
let isUpdating = false,
|
||||||
@@ -70,14 +76,16 @@
|
|||||||
confirm_password = '';
|
confirm_password = '';
|
||||||
|
|
||||||
/** @type {Object.<string, App.Locals['licence_categories']>} */
|
/** @type {Object.<string, App.Locals['licence_categories']>} */
|
||||||
$: groupedCategories = groupCategories(licence_categories);
|
$: groupedCategories = licence_categories ? groupCategories(licence_categories) : {};
|
||||||
$: subscriptionModelOptions = subscriptions.map((sub) => ({
|
$: subscriptionModelOptions = subscriptions
|
||||||
|
? subscriptions.map((sub) => ({
|
||||||
value: sub?.name ?? '',
|
value: sub?.name ?? '',
|
||||||
label: sub?.name ?? ''
|
label: sub?.name ?? ''
|
||||||
}));
|
}))
|
||||||
$: selectedSubscriptionModel =
|
: [];
|
||||||
subscriptions.find((sub) => sub?.name === user.membership?.subscription_model.name) || null;
|
$: selectedSubscriptionModel = subscriptions
|
||||||
|
? subscriptions.find((sub) => sub?.name === user.membership?.subscription.name) || null
|
||||||
|
: null;
|
||||||
/**
|
/**
|
||||||
* creates groups of categories depending on the first letter
|
* creates groups of categories depending on the first letter
|
||||||
* @param {App.Locals['licence_categories']} categories - the categories to sort and group
|
* @param {App.Locals['licence_categories']} categories - the categories to sort and group
|
||||||
@@ -99,17 +107,25 @@
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {import('../../routes/auth/about/[id]/$types').SubmitFunction} */
|
/** @type {import('@sveltejs/kit').SubmitFunction} */
|
||||||
const handleUpdate = async () => {
|
const handleUpdate = ({ cancel }) => {
|
||||||
|
if (!submit_form) {
|
||||||
|
cancel();
|
||||||
|
dispatch('close');
|
||||||
|
return;
|
||||||
|
}
|
||||||
isUpdating = true;
|
isUpdating = true;
|
||||||
|
|
||||||
return async ({ result }) => {
|
return async ({ result }) => {
|
||||||
isUpdating = false;
|
isUpdating = false;
|
||||||
|
|
||||||
if (result.type === 'success' || result.type === 'redirect') {
|
if (result.type === 'success' || result.type === 'redirect') {
|
||||||
dispatch('close');
|
dispatch('close');
|
||||||
} else {
|
} else {
|
||||||
document.querySelector('.modal .container')?.scrollTo({ top: 0, behavior: 'smooth' });
|
document.querySelector('.modal .container')?.scrollTo({ top: 0, behavior: 'smooth' });
|
||||||
}
|
}
|
||||||
await applyAction(result);
|
console.log('submitting');
|
||||||
|
return submit_form ? await applyAction(result) : undefined;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@@ -117,7 +133,18 @@
|
|||||||
{#if isLoading}
|
{#if isLoading}
|
||||||
<SmallLoader width={30} message={$t('loading.user_data')} />
|
<SmallLoader width={30} message={$t('loading.user_data')} />
|
||||||
{:else if user}
|
{:else if user}
|
||||||
<form class="content" action="?/updateUser" method="POST" use:enhance={handleUpdate}>
|
<form
|
||||||
|
class="content"
|
||||||
|
action="?/updateUser"
|
||||||
|
method="POST"
|
||||||
|
use:enhance={handleUpdate}
|
||||||
|
on:submit={(/** @type{SubmitEvent}*/ e) => {
|
||||||
|
if (!submit_form) {
|
||||||
|
e.preventDefault();
|
||||||
|
dispatch('close');
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
<input name="user[id]" type="hidden" bind:value={user.id} />
|
<input name="user[id]" type="hidden" bind:value={user.id} />
|
||||||
<h1 class="step-title" style="text-align: center;">
|
<h1 class="step-title" style="text-align: center;">
|
||||||
{user.id ? $t('user.edit') : $t('user.create')}
|
{user.id ? $t('user.edit') : $t('user.create')}
|
||||||
@@ -229,7 +256,6 @@
|
|||||||
bind:value={user.phone}
|
bind:value={user.phone}
|
||||||
placeholder={$t('placeholder.phone')}
|
placeholder={$t('placeholder.phone')}
|
||||||
/>
|
/>
|
||||||
{#if hasPrivilige(user, PERMISSIONS.Member)}
|
|
||||||
<InputField
|
<InputField
|
||||||
name="user[dateofbirth]"
|
name="user[dateofbirth]"
|
||||||
type="date"
|
type="date"
|
||||||
@@ -238,7 +264,6 @@
|
|||||||
placeholder={$t('placeholder.dateofbirth')}
|
placeholder={$t('placeholder.dateofbirth')}
|
||||||
readonly={readonlyUser}
|
readonly={readonlyUser}
|
||||||
/>
|
/>
|
||||||
{/if}
|
|
||||||
<InputField
|
<InputField
|
||||||
name="user[address]"
|
name="user[address]"
|
||||||
label={$t('address')}
|
label={$t('address')}
|
||||||
@@ -271,7 +296,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if hasPrivilige(user, PERMISSIONS.Member)}
|
{#if hasPrivilige(user, PERMISSIONS.Member) && user.licence}
|
||||||
<div class="tab-content" style="display: {activeTab === 'licence' ? 'block' : 'none'}">
|
<div class="tab-content" style="display: {activeTab === 'licence' ? 'block' : 'none'}">
|
||||||
<InputField
|
<InputField
|
||||||
name="user[licence][status]"
|
name="user[licence][status]"
|
||||||
@@ -342,7 +367,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="tab-content" style="display: {activeTab === 'membership' ? 'block' : 'none'}">
|
<div
|
||||||
|
class="tab-content"
|
||||||
|
style="display: {activeTab === 'membership' && subscriptions ? 'block' : 'none'}"
|
||||||
|
>
|
||||||
<InputField
|
<InputField
|
||||||
name="user[membership][status]"
|
name="user[membership][status]"
|
||||||
type="select"
|
type="select"
|
||||||
@@ -352,10 +380,10 @@
|
|||||||
readonly={readonlyUser}
|
readonly={readonlyUser}
|
||||||
/>
|
/>
|
||||||
<InputField
|
<InputField
|
||||||
name="user[membership][subscription_model][name]"
|
name="user[membership][subscription][name]"
|
||||||
type="select"
|
type="select"
|
||||||
label={$t('subscription.subscription')}
|
label={$t('subscriptions.subscription')}
|
||||||
bind:value={user.membership.subscription_model.name}
|
bind:value={user.membership.subscription.name}
|
||||||
options={subscriptionModelOptions}
|
options={subscriptionModelOptions}
|
||||||
readonly={readonlyUser || !hasPrivilige(user, PERMISSIONS.Member)}
|
readonly={readonlyUser || !hasPrivilige(user, PERMISSIONS.Member)}
|
||||||
/>
|
/>
|
||||||
@@ -363,22 +391,22 @@
|
|||||||
{#if hasPrivilige(user, PERMISSIONS.Member)}
|
{#if hasPrivilige(user, PERMISSIONS.Member)}
|
||||||
<div class="subscription-column">
|
<div class="subscription-column">
|
||||||
<p>
|
<p>
|
||||||
<strong>{$t('subscription.monthly_fee')}:</strong>
|
<strong>{$t('subscriptions.monthly_fee')}:</strong>
|
||||||
{selectedSubscriptionModel?.monthly_fee || '-'} €
|
{selectedSubscriptionModel?.monthly_fee || '-'} €
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<strong>{$t('subscription.hourly_rate')}:</strong>
|
<strong>{$t('subscriptions.hourly_rate')}:</strong>
|
||||||
{selectedSubscriptionModel?.hourly_rate || '-'} €
|
{selectedSubscriptionModel?.hourly_rate || '-'} €
|
||||||
</p>
|
</p>
|
||||||
{#if selectedSubscriptionModel?.included_hours_per_year}
|
{#if selectedSubscriptionModel?.included_hours_per_year}
|
||||||
<p>
|
<p>
|
||||||
<strong>{$t('subscription.included_hours_per_year')}:</strong>
|
<strong>{$t('subscriptions.included_hours_per_year')}:</strong>
|
||||||
{selectedSubscriptionModel?.included_hours_per_year}
|
{selectedSubscriptionModel?.included_hours_per_year}
|
||||||
</p>
|
</p>
|
||||||
{/if}
|
{/if}
|
||||||
{#if selectedSubscriptionModel?.included_hours_per_month}
|
{#if selectedSubscriptionModel?.included_hours_per_month}
|
||||||
<p>
|
<p>
|
||||||
<strong>{$t('subscription.included_hours_per_month')}:</strong>
|
<strong>{$t('subscriptions.included_hours_per_month')}:</strong>
|
||||||
{selectedSubscriptionModel?.included_hours_per_month}
|
{selectedSubscriptionModel?.included_hours_per_month}
|
||||||
</p>
|
</p>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -391,7 +419,7 @@
|
|||||||
</p>
|
</p>
|
||||||
{#if selectedSubscriptionModel?.conditions}
|
{#if selectedSubscriptionModel?.conditions}
|
||||||
<p>
|
<p>
|
||||||
<strong>{$t('subscription.conditions')}:</strong>
|
<strong>{$t('subscriptions.conditions')}:</strong>
|
||||||
{selectedSubscriptionModel?.conditions}
|
{selectedSubscriptionModel?.conditions}
|
||||||
</p>
|
</p>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -7,11 +7,12 @@ export default {
|
|||||||
5: 'Passiv'
|
5: 'Passiv'
|
||||||
},
|
},
|
||||||
userRole: {
|
userRole: {
|
||||||
|
'-5': 'Unfallgegner',
|
||||||
0: 'Sponsor',
|
0: 'Sponsor',
|
||||||
1: 'Mitglied',
|
1: 'Mitglied',
|
||||||
2: 'Betrachter',
|
2: 'Betrachter',
|
||||||
4: 'Bearbeiter',
|
4: 'Bearbeiter',
|
||||||
8: 'Adm/endinistrator'
|
8: 'Administrator'
|
||||||
},
|
},
|
||||||
placeholder: {
|
placeholder: {
|
||||||
car_name: 'Hat das Fahrzeug einen Namen?',
|
car_name: 'Hat das Fahrzeug einen Namen?',
|
||||||
@@ -75,7 +76,7 @@ export default {
|
|||||||
validation: {
|
validation: {
|
||||||
invalid: 'ungültig',
|
invalid: 'ungültig',
|
||||||
invalid_user_id: 'Nutzer ID ungültig',
|
invalid_user_id: 'Nutzer ID ungültig',
|
||||||
invalid_subscription_model: 'Model nicht gefunden',
|
invalid_subscription: 'Model nicht gefunden',
|
||||||
user_not_found: '{field} konnte nicht gefunden werden',
|
user_not_found: '{field} konnte nicht gefunden werden',
|
||||||
invalid_user_data: 'Nutzerdaten ungültig',
|
invalid_user_data: 'Nutzerdaten ungültig',
|
||||||
user_not_found_or_wrong_password: 'Existiert nicht oder falsches Passwort',
|
user_not_found_or_wrong_password: 'Existiert nicht oder falsches Passwort',
|
||||||
@@ -141,7 +142,7 @@ export default {
|
|||||||
role: 'Nutzerrolle',
|
role: 'Nutzerrolle',
|
||||||
supporter: 'Sponsor'
|
supporter: 'Sponsor'
|
||||||
},
|
},
|
||||||
subscription: {
|
subscriptions: {
|
||||||
name: 'Modellname',
|
name: 'Modellname',
|
||||||
edit: 'Modell bearbeiten',
|
edit: 'Modell bearbeiten',
|
||||||
create: 'Modell erstellen',
|
create: 'Modell erstellen',
|
||||||
@@ -176,6 +177,8 @@ export default {
|
|||||||
user_deletion: 'Soll der Nutzer {firstname} {lastname} wirklich gelöscht werden?',
|
user_deletion: 'Soll der Nutzer {firstname} {lastname} wirklich gelöscht werden?',
|
||||||
subscription_deletion: 'Soll das Tarifmodell {name} wirklich gelöscht werden?',
|
subscription_deletion: 'Soll das Tarifmodell {name} wirklich gelöscht werden?',
|
||||||
car_deletion: 'Soll das Fahrzeug {name} wirklich gelöscht werden?',
|
car_deletion: 'Soll das Fahrzeug {name} wirklich gelöscht werden?',
|
||||||
|
insurance_deletion: 'Soll die Versicherung {name} wirklich gelöscht werden?',
|
||||||
|
damage_deletion: 'Soll der Schaden {name} wirklich gelöscht werden?',
|
||||||
backend_access: 'Soll {firstname} {lastname} Backend Zugriff gewährt werden?'
|
backend_access: 'Soll {firstname} {lastname} Backend Zugriff gewährt werden?'
|
||||||
},
|
},
|
||||||
cancel: 'Abbrechen',
|
cancel: 'Abbrechen',
|
||||||
@@ -192,7 +195,7 @@ export default {
|
|||||||
supporter: 'Sponsoren',
|
supporter: 'Sponsoren',
|
||||||
mandate_date_signed: 'Mandatserteilungsdatum',
|
mandate_date_signed: 'Mandatserteilungsdatum',
|
||||||
licence_categories: 'Führerscheinklassen',
|
licence_categories: 'Führerscheinklassen',
|
||||||
subscription_model: 'Mitgliedschatfsmodell',
|
subscription: 'Mitgliedschatfsmodell',
|
||||||
licence: 'Führerschein',
|
licence: 'Führerschein',
|
||||||
licence_number: 'Führerscheinnummer',
|
licence_number: 'Führerscheinnummer',
|
||||||
insurance: 'Versicherung',
|
insurance: 'Versicherung',
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ export default {
|
|||||||
validation: {
|
validation: {
|
||||||
invalid: 'Invalid',
|
invalid: 'Invalid',
|
||||||
invalid_user_id: 'Invalid user ID',
|
invalid_user_id: 'Invalid user ID',
|
||||||
invalid_subscription_model: 'Model not found',
|
invalid_subscription: 'Model not found',
|
||||||
user_not_found: '{field} could not be found',
|
user_not_found: '{field} could not be found',
|
||||||
invalid_user_data: 'Invalid user data',
|
invalid_user_data: 'Invalid user data',
|
||||||
user_not_found_or_wrong_password: 'Does not exist or wrong password',
|
user_not_found_or_wrong_password: 'Does not exist or wrong password',
|
||||||
@@ -128,7 +128,7 @@ export default {
|
|||||||
role: 'User Role',
|
role: 'User Role',
|
||||||
supporter: 'Sponsor'
|
supporter: 'Sponsor'
|
||||||
},
|
},
|
||||||
subscription: {
|
subscriptions: {
|
||||||
name: 'Model Name',
|
name: 'Model Name',
|
||||||
edit: 'Edit Model',
|
edit: 'Edit Model',
|
||||||
create: 'Create Model',
|
create: 'Create Model',
|
||||||
@@ -160,7 +160,7 @@ export default {
|
|||||||
supporter: 'Sponsors',
|
supporter: 'Sponsors',
|
||||||
mandate_date_signed: 'Mandate Signing Date',
|
mandate_date_signed: 'Mandate Signing Date',
|
||||||
licence_categories: 'Driver’s licence Categories',
|
licence_categories: 'Driver’s licence Categories',
|
||||||
subscription_model: 'Membership Model',
|
subscription: 'Membership Model',
|
||||||
licence: 'Driver’s licence',
|
licence: 'Driver’s licence',
|
||||||
licence_number: 'Driver’s licence Number',
|
licence_number: 'Driver’s licence Number',
|
||||||
issued_date: 'Issue Date',
|
issued_date: 'Issue Date',
|
||||||
|
|||||||
@@ -11,4 +11,5 @@ export const PERMISSIONS = {
|
|||||||
Super: 8
|
Super: 8
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SUPPORTER_SUBSCRIPTION_MODEL_NAME = 'Keins';
|
export const SUPPORTER_SUBSCRIPTION_NAME = 'Keins';
|
||||||
|
export const OPPONENT_SUBSCRIPTION_NAME = 'Keins';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// src/lib/utils/defaults.js
|
// src/lib/utils/defaults.js
|
||||||
|
|
||||||
import { SUPPORTER_SUBSCRIPTION_MODEL_NAME } from './constants';
|
import { OPPONENT_SUBSCRIPTION_NAME, SUPPORTER_SUBSCRIPTION_NAME } from './constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {App.Types['subscription']}
|
* @returns {App.Types['subscription']}
|
||||||
@@ -28,7 +28,7 @@ export function defaultMembership() {
|
|||||||
start_date: '',
|
start_date: '',
|
||||||
end_date: '',
|
end_date: '',
|
||||||
parent_member_id: 0,
|
parent_member_id: 0,
|
||||||
subscription_model: defaultSubscription()
|
subscription: defaultSubscription()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,31 +93,25 @@ export function defaultUser() {
|
|||||||
* @returns {App.Locals['user']}
|
* @returns {App.Locals['user']}
|
||||||
*/
|
*/
|
||||||
export function defaultSupporter() {
|
export function defaultSupporter() {
|
||||||
let supporter = {
|
let supporter = defaultUser();
|
||||||
id: 0,
|
supporter.status = 5;
|
||||||
email: '',
|
supporter.role_id = 0;
|
||||||
first_name: '',
|
supporter.licence = null;
|
||||||
last_name: '',
|
supporter.membership.subscription.name = SUPPORTER_SUBSCRIPTION_NAME;
|
||||||
password: '',
|
|
||||||
phone: '',
|
|
||||||
address: '',
|
|
||||||
zip_code: '',
|
|
||||||
city: '',
|
|
||||||
company: '',
|
|
||||||
dateofbirth: '',
|
|
||||||
notes: '',
|
|
||||||
profile_picture: '',
|
|
||||||
payment_status: 0,
|
|
||||||
status: 5,
|
|
||||||
role_id: 0,
|
|
||||||
membership: defaultMembership(),
|
|
||||||
licence: defaultLicence(),
|
|
||||||
bank_account: defaultBankAccount()
|
|
||||||
};
|
|
||||||
supporter.membership.subscription_model.name = SUPPORTER_SUBSCRIPTION_MODEL_NAME;
|
|
||||||
return supporter;
|
return supporter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {App.Locals['user']}
|
||||||
|
*/
|
||||||
|
export function defaultOpponent() {
|
||||||
|
let opponent = defaultUser();
|
||||||
|
opponent.status = 5;
|
||||||
|
opponent.role_id = -1;
|
||||||
|
opponent.licence = null;
|
||||||
|
opponent.membership.subscription.name = OPPONENT_SUBSCRIPTION_NAME;
|
||||||
|
return opponent;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @returns {App.Types['location']}
|
* @returns {App.Types['location']}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -62,44 +62,16 @@ export function formDataToObject(formData) {
|
|||||||
* @param {{ object: Partial<App.Locals['user']>, confirm_password: string} } rawData - The raw form data object
|
* @param {{ object: Partial<App.Locals['user']>, confirm_password: string} } rawData - The raw form data object
|
||||||
* @returns {{ user: Partial<App.Locals['user']> }} Processed user data
|
* @returns {{ user: Partial<App.Locals['user']> }} Processed user data
|
||||||
*/
|
*/
|
||||||
export function processUserFormData(rawData) {
|
export function processMembershipFormData(membership) {
|
||||||
/** @type {{ user: Partial<App.Locals['user']> }} */
|
return {
|
||||||
let processedData = {
|
id: Number(membership.id) || 0,
|
||||||
user: {
|
status: Number(membership.status),
|
||||||
id: Number(rawData.object.id) || 0,
|
start_date: toRFC3339(String(membership.start_date || '')),
|
||||||
status: Number(rawData.object.status),
|
end_date: toRFC3339(String(membership.end_date || '')),
|
||||||
role_id: Number(rawData.object.role_id),
|
parent_member_id: Number(membership.parent_member_id) || 0,
|
||||||
first_name: String(rawData.object.first_name),
|
subscription: processSubscriptionFormData(membership.subscription)
|
||||||
last_name: String(rawData.object.last_name),
|
};
|
||||||
email: String(rawData.object.email),
|
}
|
||||||
phone: String(rawData.object.phone || ''),
|
|
||||||
company: String(rawData.object.company || ''),
|
|
||||||
dateofbirth: toRFC3339(String(rawData.object.dateofbirth || '')),
|
|
||||||
address: String(rawData.object.address || ''),
|
|
||||||
zip_code: String(rawData.object.zip_code || ''),
|
|
||||||
city: String(rawData.object.city || ''),
|
|
||||||
notes: String(rawData.object.notes || ''),
|
|
||||||
profile_picture: String(rawData.object.profile_picture || ''),
|
|
||||||
|
|
||||||
membership: {
|
|
||||||
id: Number(rawData.object.membership?.id) || 0,
|
|
||||||
status: Number(rawData.object.membership?.status),
|
|
||||||
start_date: toRFC3339(String(rawData.object.membership?.start_date || '')),
|
|
||||||
end_date: toRFC3339(String(rawData.object.membership?.end_date || '')),
|
|
||||||
parent_member_id: Number(rawData.object.membership?.parent_member_id) || 0,
|
|
||||||
subscription_model: {
|
|
||||||
id: Number(rawData.object.membership?.subscription_model?.id) || 0,
|
|
||||||
name: String(rawData.object.membership?.subscription_model?.name) || '',
|
|
||||||
details: String(rawData.object.membership?.subscription_model?.details) || '',
|
|
||||||
conditions: String(rawData.object.membership?.subscription_model?.conditions) || '',
|
|
||||||
hourly_rate: Number(rawData.object.membership?.subscription_model?.hourly_rate) || 0,
|
|
||||||
monthly_fee: Number(rawData.object.membership?.subscription_model?.monthly_fee) || 0,
|
|
||||||
included_hours_per_month:
|
|
||||||
Number(rawData.object.membership?.subscription_model?.included_hours_per_month) || 0,
|
|
||||||
included_hours_per_year:
|
|
||||||
Number(rawData.object.membership?.subscription_model?.included_hours_per_year) || 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
licence: {
|
licence: {
|
||||||
id: Number(rawData.object.licence?.id) || 0,
|
id: Number(rawData.object.licence?.id) || 0,
|
||||||
@@ -143,22 +115,20 @@ export function processUserFormData(rawData) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes the raw form data into the expected subscription data structure
|
* Processes the raw form data into the expected subscription data structure
|
||||||
* @param {{ object: Partial<App.Types['subscription']>, confirm_password: string }} rawData - The raw form data object
|
* @param {Partial<App.Types['subscription']>} subscription - The raw form data object
|
||||||
* @returns {{ subscription: Partial<App.Types['subscription']> }} Processed user data
|
* @returns {App.Types['subscription']} Processed user data
|
||||||
*/
|
*/
|
||||||
export function processSubscriptionFormData(rawData) {
|
export function processSubscriptionFormData(subscription) {
|
||||||
/** @type {{ subscription: Partial<App.Types['subscription']> }} */
|
/** @type {Partial<App.Types['subscription']>} */
|
||||||
let processedData = {
|
let processedData = {
|
||||||
subscription: {
|
id: Number(subscription.id) || 0,
|
||||||
id: Number(rawData.object.id) || 0,
|
name: String(subscription.name) || '',
|
||||||
name: String(rawData.object.name) || '',
|
details: String(subscription.details) || '',
|
||||||
details: String(rawData.object.details) || '',
|
conditions: String(subscription.conditions) || '',
|
||||||
conditions: String(rawData.object.conditions) || '',
|
hourly_rate: Number(subscription.hourly_rate) || 0,
|
||||||
hourly_rate: Number(rawData.object.hourly_rate) || 0,
|
monthly_fee: Number(subscription.monthly_fee) || 0,
|
||||||
monthly_fee: Number(rawData.object.monthly_fee) || 0,
|
included_hours_per_month: Number(subscription.included_hours_per_month) || 0,
|
||||||
included_hours_per_month: Number(rawData.object.included_hours_per_month) || 0,
|
included_hours_per_year: Number(subscription.included_hours_per_year) || 0
|
||||||
included_hours_per_year: Number(rawData.object.included_hours_per_year) || 0
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
const clean = JSON.parse(JSON.stringify(processedData), (key, value) =>
|
const clean = JSON.parse(JSON.stringify(processedData), (key, value) =>
|
||||||
value !== null && value !== '' ? value : undefined
|
value !== null && value !== '' ? value : undefined
|
||||||
|
|||||||
@@ -87,10 +87,11 @@ export const actions = {
|
|||||||
updateSubscription: async ({ request, fetch, cookies }) => {
|
updateSubscription: async ({ request, fetch, cookies }) => {
|
||||||
let formData = await request.formData();
|
let formData = await request.formData();
|
||||||
|
|
||||||
const rawData = formDataToObject(formData);
|
const rawFormData = formDataToObject(formData);
|
||||||
const processedData = processSubscriptionFormData(rawData);
|
const rawSubscription = /** @type {Partial<App.Types['subscription']>} */ (rawFormData.object);
|
||||||
|
const subscription = processSubscriptionFormData(rawSubscription);
|
||||||
|
|
||||||
const isCreating = !processedData.subscription.id || processedData.subscription.id === 0;
|
const isCreating = !subscription.id || subscription.id === 0;
|
||||||
console.log('Is creating: ', isCreating);
|
console.log('Is creating: ', isCreating);
|
||||||
const apiURL = `${BASE_API_URI}/auth/subscriptions`;
|
const apiURL = `${BASE_API_URI}/auth/subscriptions`;
|
||||||
|
|
||||||
@@ -102,7 +103,7 @@ export const actions = {
|
|||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
Cookie: `jwt=${cookies.get('jwt')}`
|
Cookie: `jwt=${cookies.get('jwt')}`
|
||||||
},
|
},
|
||||||
body: JSON.stringify(processedData.subscription)
|
body: JSON.stringify(subscription)
|
||||||
};
|
};
|
||||||
|
|
||||||
const res = await fetch(apiURL, requestOptions);
|
const res = await fetch(apiURL, requestOptions);
|
||||||
|
|||||||
@@ -83,9 +83,7 @@
|
|||||||
user.licence?.number?.toLowerCase()
|
user.licence?.number?.toLowerCase()
|
||||||
].some((field) => field?.includes(term));
|
].some((field) => field?.includes(term));
|
||||||
|
|
||||||
const subscriptionMatch = user.membership?.subscription_model?.name
|
const subscriptionMatch = user.membership?.subscription?.name?.toLowerCase().includes(term);
|
||||||
?.toLowerCase()
|
|
||||||
.includes(term);
|
|
||||||
|
|
||||||
const licenceCategoryMatch = user.licence?.categories?.some((cat) =>
|
const licenceCategoryMatch = user.licence?.categories?.some((cat) =>
|
||||||
cat.category.toLowerCase().includes(term)
|
cat.category.toLowerCase().includes(term)
|
||||||
@@ -277,8 +275,8 @@
|
|||||||
<td>{user.email}</td>
|
<td>{user.email}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>{$t('subscription.subscription')}</th>
|
<th>{$t('subscriptions.subscription')}</th>
|
||||||
<td>{user.membership?.subscription_model?.name}</td>
|
<td>{user.membership?.subscription?.name}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>{$t('status')}</th>
|
<th>{$t('status')}</th>
|
||||||
@@ -462,7 +460,7 @@
|
|||||||
<span class="nav-badge"
|
<span class="nav-badge"
|
||||||
>{members.filter(
|
>{members.filter(
|
||||||
(/** @type{App.Locals['user']}*/ user) =>
|
(/** @type{App.Locals['user']}*/ user) =>
|
||||||
user.membership?.subscription_model?.name === subscription.name
|
user.membership?.subscription?.name === subscription.name
|
||||||
).length}</span
|
).length}</span
|
||||||
>
|
>
|
||||||
</summary>
|
</summary>
|
||||||
@@ -514,7 +512,8 @@
|
|||||||
<i class="fas fa-edit"></i>
|
<i class="fas fa-edit"></i>
|
||||||
{$t('edit')}
|
{$t('edit')}
|
||||||
</button>
|
</button>
|
||||||
{#if !members.some(/** @param{App.Locals['user']} user */ (user) => user.membership?.subscription_model?.id === subscription.id)}
|
{/if}
|
||||||
|
{#if !members.some(/** @param{App.Locals['user']} user */ (user) => user.membership?.subscription?.id === subscription.id)}
|
||||||
<form
|
<form
|
||||||
method="POST"
|
method="POST"
|
||||||
action="?/subscriptionDelete"
|
action="?/subscriptionDelete"
|
||||||
@@ -528,20 +527,6 @@
|
|||||||
?.scrollTo({ top: 0, behavior: 'smooth' });
|
?.scrollTo({ top: 0, behavior: 'smooth' });
|
||||||
await applyAction(result);
|
await applyAction(result);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}}
|
|
||||||
on:submit|preventDefault={(/** @type {SubmitEvent} */ e) => {
|
|
||||||
if (
|
|
||||||
!confirm(
|
|
||||||
$t('dialog.subscription_deletion', {
|
|
||||||
values: {
|
|
||||||
name: subscription.name || ''
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
e.preventDefault(); // Cancel form submission if user declines
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<input type="hidden" name="subscription[id]" value={subscription.id} />
|
<input type="hidden" name="subscription[id]" value={subscription.id} />
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ type Membership struct {
|
|||||||
StartDate time.Time `json:"start_date"`
|
StartDate time.Time `json:"start_date"`
|
||||||
EndDate time.Time `json:"end_date"`
|
EndDate time.Time `json:"end_date"`
|
||||||
Status int8 `json:"status" binding:"number,safe_content"`
|
Status int8 `json:"status" binding:"number,safe_content"`
|
||||||
SubscriptionModel SubscriptionModel `gorm:"foreignKey:SubscriptionModelID" json:"subscription_model"`
|
SubscriptionModel SubscriptionModel `gorm:"foreignKey:SubscriptionModelID" json:"subscription"`
|
||||||
SubscriptionModelID uint `json:"subsription_model_id"`
|
SubscriptionModelID uint `json:"subsription_model_id"`
|
||||||
ParentMembershipID uint `json:"parent_member_id" binding:"omitempty,omitnil,number"`
|
ParentMembershipID uint `json:"parent_member_id" binding:"omitempty,omitnil,number"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -441,7 +441,7 @@ func (u *User) Safe() map[string]interface{} {
|
|||||||
"start_date": u.Membership.StartDate,
|
"start_date": u.Membership.StartDate,
|
||||||
"end_date": u.Membership.EndDate,
|
"end_date": u.Membership.EndDate,
|
||||||
"status": u.Membership.Status,
|
"status": u.Membership.Status,
|
||||||
"subscription_model": map[string]interface{}{
|
"subscription": map[string]interface{}{
|
||||||
"id": u.Membership.SubscriptionModel.ID,
|
"id": u.Membership.SubscriptionModel.ID,
|
||||||
"name": u.Membership.SubscriptionModel.Name,
|
"name": u.Membership.SubscriptionModel.Name,
|
||||||
"details": u.Membership.SubscriptionModel.Details,
|
"details": u.Membership.SubscriptionModel.Details,
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ var Responses = struct {
|
|||||||
InternalServerError: "server.error.internal_server_error",
|
InternalServerError: "server.error.internal_server_error",
|
||||||
InvalidJSON: "server.error.invalid_json",
|
InvalidJSON: "server.error.invalid_json",
|
||||||
InvalidUserID: "server.validation.invalid_user_id",
|
InvalidUserID: "server.validation.invalid_user_id",
|
||||||
InvalidSubscriptionModel: "server.validation.invalid_subscription_model",
|
InvalidSubscriptionModel: "server.validation.invalid_subscription",
|
||||||
Unauthorized: "server.error.unauthorized",
|
Unauthorized: "server.error.unauthorized",
|
||||||
UserNotFoundWrongPassword: "server.validation.user_not_found_or_wrong_password",
|
UserNotFoundWrongPassword: "server.validation.user_not_found_or_wrong_password",
|
||||||
JwtGenerationFailed: "server.error.jwt_generation_failed",
|
JwtGenerationFailed: "server.error.jwt_generation_failed",
|
||||||
@@ -82,7 +82,7 @@ var Responses = struct {
|
|||||||
Fields: ValidationFields{
|
Fields: ValidationFields{
|
||||||
General: "server.general",
|
General: "server.general",
|
||||||
ParentMembershipID: "parent_membership_id",
|
ParentMembershipID: "parent_membership_id",
|
||||||
SubscriptionModel: "subscription_model",
|
SubscriptionModel: "subscription",
|
||||||
Login: "user.login",
|
Login: "user.login",
|
||||||
Email: "user.email",
|
Email: "user.email",
|
||||||
User: "user.user",
|
User: "user.user",
|
||||||
|
|||||||
Reference in New Issue
Block a user