Skip to content

Commit

Permalink
feat(dashboard/components): added FormSection component
Browse files Browse the repository at this point in the history
feat(dashboard/user-profile): removed dialog for changing pin, added form section for changing pin
  • Loading branch information
CodeNamedRobin committed Aug 30, 2024
1 parent 5764a5d commit 4e6c8f3
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 12 deletions.
77 changes: 77 additions & 0 deletions apps/dashboard/src/components/FormSection.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<template>
<div class="flex flex-column gap-2">
<div class="flex flex-row align-items-center">
<h4 class="flex-grow-1">{{ header }}</h4>
<div class="flex flex-row ">
<Button v-if="simpleSave" icon="pi pi-save" class="my-0" @click="toggleEdit(true)" label="Save" ></Button>
<Button v-else-if="!edit" icon="pi pi-pencil" class="my-0" @click="toggleEdit(true)" label="Edit" ></Button>
<div v-else class="flex flex-row gap-2">
<Button icon ="pi pi-check" class="my-0" @click="handleSave" />
<Button icon="pi pi-times" class="my-0" @click="cancel" />
</div>
</div>
</div>
</div>
<slot :edit="edit" />
<Divider class="w-full" v-if="divider" />
</template>

<script setup lang="ts">
import {onMounted, ref} from "vue";
import Divider from "primevue/divider";
import Button from "primevue/button";
const props = defineProps({
header: {
type: String,
required: true
},
enableEdit: {
type: Boolean,
required: false,
default: false,
},
modelValue: {
type: Boolean,
required: false,
},
divider: {
type: Boolean,
required: false,
default: false,
},
simpleSave: {
type: Boolean,
required: false,
default: false,
}
});
const emit = defineEmits(['update:modelValue', 'save', 'cancel']);
const edit = ref(props.modelValue);
const toggleEdit = (value: boolean) => {
edit.value = value;
emit('update:modelValue', value);
};
const cancel = () => {
emit('cancel');
toggleEdit(false);
};
const handleSave = () => {
emit('save');
toggleEdit(false);
};
onMounted(() => {
if (props.simpleSave) {
toggleEdit(true);
}
});
</script>

<style scoped>
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
:action="undefined"
class="w-5"
>

<div class="flex flex-column">
<h4 class="mt-0">{{ t('userSettings.changeCredentials') }}</h4>
<div class="flex flex-row align-items-center w-11">
<p class="flex-grow-1 my-1">{{ t('userSettings.changePin') }}</p>
<i
class="pi pi-external-link text-gray-500 flex align-items-center"
@click="showPinDialog = true"
/>
</div>
<FormSection
:header="t('userSettings.changePin')"
@cancel="pinForm.context.resetForm"
@save="pinForm.submit"
:enableEdit="true"
:simpleSave="true"
@update:modelValue="editPin = $event"
divider>
<ChangePinForm :form="pinForm" :edit="editPin"/>
</FormSection>
<div class="flex flex-row align-items-center w-11">
<p class="flex-grow-1 my-1">{{ t('userSettings.changePassword') }}</p>
<i
Expand Down Expand Up @@ -41,13 +44,12 @@
<InputSwitch />
</div>
</div>
</CardComponent>

</CardComponent>
<FormDialog
v-model="showPinDialog"
:form="pinForm"
:header="$t('userSettings.changePin')"

>
<template #form="slotProps">
<ChangePinForm :form="slotProps.form" @submit:success="showPinDialog = false"/>
Expand All @@ -67,6 +69,7 @@ import ChangePinForm from "@/modules/user/components/forms/ChangePinForm.vue";
import FormDialog from "@/components/FormDialog.vue";
import { editPinSchema } from "@/utils/validation-schema";
import { schemaToForm } from "@/utils/formUtils";
import FormSection from "@/components/FormSection.vue";
defineProps({
user: {
Expand All @@ -78,6 +81,9 @@ defineProps({
const { t } = useI18n();
const showPinDialog = ref(false);
const pinForm = schemaToForm(editPinSchema);
const editPin = ref(true);
</script>

<style scoped></style>
13 changes: 11 additions & 2 deletions apps/dashboard/src/modules/user/components/forms/ChangePinForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
:attributes="form.model.pin.attr.value"
@update:value="form.context.setFieldValue('pin', $event)"
:errors="form.context.errors.value.pin"
id="pin" type="pin"/>
id="pin" type="pin"
:disabled="!edit"
/>
<InputSpan :label="t('profile.pinConfirm')"
:value="form.model.pinConfirm.value.value"
:attributes="form.model.pinConfirm.attr.value"
@update:value="form.context.setFieldValue('pinConfirm', $event)"
:errors="form.context.errors.value.pinConfirm"
id="pinConfirm" type="pin"/>
id="pinConfirm" type="pin"
:disabled="!edit"
/>
</div>
</template>

Expand All @@ -32,6 +36,11 @@ const props = defineProps({
type: Object as PropType<Form<yup.InferType<typeof editPinSchema>>>,
required: true,
},
edit: {
type: Boolean,
required: false,
default: false,
},
});
const { t } = useI18n();
Expand Down

0 comments on commit 4e6c8f3

Please sign in to comment.