Skip to content

Commit

Permalink
last refactor bits minus downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
pariah committed May 8, 2024
1 parent a7ee962 commit 3bf1fe8
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 133 deletions.
33 changes: 15 additions & 18 deletions pages/addUser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,28 @@
div
.rounded-lg.p-8.bg-zinc-400.w-full
.bg-white.rounded-lg.p-8
form(@submit.prevent='createUser')
.form-group
label(for='username') Username:
input(name='username' v-model='username')
.form-group
label(for='permission') Permission:
input(name='permission' v-model='permission')
br
br
button(type='submit' @click="navigateTo('/admin')") Create User
form.flex.flex-col.mt-2.mx-auto(class="w-1/2" @submit.prevent='createUser' @keydown.enter.prevent)
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap.self-center(for='prefix') Email:
input.rounded-2xl.p-2.border.border-gray-400(v-model='user.username')
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap.self-center(for='prefix') Role:
select.mt-2.rounded-lg.p-5.bg-white(v-model="user.permission")
option(value="VIEWER") VIEWER
option(value="EDITOR") EDITOR
option(value="ADMIN") ADMIN
button.self-end.bg-theme-primary.text-white.rounded-md.text-md.p-4.w-min.h-min.whitespace-nowrap(type='submit') Create User
</template>

<script setup>
const username = ref('');
const permission = ref('');
const user = ref({ permission: "VIEWER" });
const createUser = async () => {
const { data } = await useFetch('/api/user', {
const response = await $fetch('/api/user', {
method: 'POST',
body: {
username: username,
permission: permission
}
body: user.value
});
router.navigate('/admin');
};
</script>

Expand Down
44 changes: 22 additions & 22 deletions pages/editContact.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,72 +7,72 @@ div
.grid.grid-cols-1.gap-5(class="md:grid-cols-2 xl:grid-cols-3")
.flex.flex-col.gap-2
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap(for='prefix') Prefix:
label.whitespace-nowrap.self-center(for='prefix') Prefix:
input.rounded-2xl.p-2.border.border-gray-400(v-model='contact.prefix')
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap(for='firstName') First Name:
label.whitespace-nowrap.self-center(for='firstName') First Name:
input.rounded-2xl.p-2.border.border-gray-400(name='firstName' v-model='contact.firstName')
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap(for='middleName') Middle Name:
label.whitespace-nowrap.self-center(for='middleName') Middle Name:
input.rounded-2xl.p-2.border.border-gray-400(v-model='contact.middleName')
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap(for='lastName') Last Name:
label.whitespace-nowrap.self-center(for='lastName') Last Name:
input.rounded-2xl.p-2.border.border-gray-400(v-model='contact.lastName')
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap(for='suffix') Suffix:
label.whitespace-nowrap.self-center(for='suffix') Suffix:
input.rounded-2xl.p-2.border.border-gray-400(v-model='contact.suffix')
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap(for='professionalTitle') Professional Title:
label.whitespace-nowrap.self-center(for='professionalTitle') Professional Title:
input.rounded-2xl.p-2.border.border-gray-400(v-model='contact.professionalTitle')
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap(for='company') Company:
label.whitespace-nowrap.self-center(for='company') Company:
input.rounded-2xl.p-2.border.border-gray-400(v-model='contact.company')
.flex.flex-col.gap-2
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap(for='address1') Address 1:
label.whitespace-nowrap.self-center(for='address1') Address 1:
input.rounded-2xl.p-2.border.border-gray-400(v-model='contact.address1')
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap(for='city') City:
label.whitespace-nowrap.self-center(for='city') City:
input.rounded-2xl.p-2.border.border-gray-400(v-model='contact.city1')
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap(for='contact') State:
label.whitespace-nowrap.self-center(for='contact') State:
input.rounded-2xl.p-2.border.border-gray-400(v-model='contact.state1')
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap(for='zipCode') Zip Code:
label.whitespace-nowrap.self-center(for='zipCode') Zip Code:
input.rounded-2xl.p-2.border.border-gray-400(v-model='contact.zipCode1')
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap(for='address1Type') Address Type:
label.whitespace-nowrap.self-center(for='address1Type') Address Type:
input.rounded-2xl.p-2.border.border-gray-400(v-model='contact.address1Type')
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap(for='address2') Address 2:
label.whitespace-nowrap.self-center(for='address2') Address 2:
input.rounded-2xl.p-2.border.border-gray-400(v-model='contact.address2')
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap(for='city2') City:
label.whitespace-nowrap.self-center(for='city2') City:
input.rounded-2xl.p-2.border.border-gray-400(v-model='contact.city2')
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap(for='state2') State:
label.whitespace-nowrap.self-center(for='state2') State:
input.rounded-2xl.p-2.border.border-gray-400(v-model='contact.state2')
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap(for='zipCode2') Zip Code:
label.whitespace-nowrap.self-center(for='zipCode2') Zip Code:
input.rounded-2xl.p-2.border.border-gray-400(v-model='contact.zipCode2')
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap(for='address2Type') Address Type:
label.whitespace-nowrap.self-center(for='address2Type') Address Type:
input.rounded-2xl.p-2.border.border-gray-400(v-model='contact.address2Type')
.flex.flex-col.gap-2
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap(for='mainPhone') Main Phone:
label.whitespace-nowrap.self-center(for='mainPhone') Main Phone:
input.rounded-2xl.p-2.border.border-gray-400(v-model='contact.mainPhone')
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap(for='directPhone') Direct Phone:
label.whitespace-nowrap.self-center(for='directPhone') Direct Phone:
input.rounded-2xl.p-2.border.border-gray-400(v-model='contact.directPhone')
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap(for='mobilePhone') Mobile Phone:
label.whitespace-nowrap.self-center(for='mobilePhone') Mobile Phone:
input.rounded-2xl.p-2.border.border-gray-400(v-model='contact.mobilePhone')
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap(for='emailAddress') Email Address:
label.whitespace-nowrap.self-center(for='emailAddress') Email Address:
input.rounded-2xl.p-2.border.border-gray-400(v-model='contact.emailAddress')
.flex.flex-col.justify-between(class="sm:flex-row")
label.whitespace-nowrap(for='narrative') Narrative:
label.whitespace-nowrap.self-center(for='narrative') Narrative:
textarea.w-max(v-model='contact.narrative')
.flex.flex-col.justify-between
Multiselect(
Expand Down
35 changes: 21 additions & 14 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,33 @@
option(value="lastWeek") Last Week
option(value="custom") Custom
option(value="allcontacts") All Contacts
div(v-if="selectedDateRange === 'custom'")
//VueDatePicker(v-model="filters.startDate" :max-date="new Date()" enable-time-picker="false")
//VueDatePicker(v-model="filters.endDate" :max-date="new Date()")
div(v-if="selectedDateRange === 'custom'")
VueDatePicker(v-model="filters.startDate" :max-date="new Date()" :enableTimePicker="false")
VueDatePicker(v-model="filters.endDate" :max-date="new Date()" :enableTimePicker="false")
.rounded-lg.p-8.bg-zinc-400.w-full.shadow-inner.flex.flex-col.gap-5
.flex.gap-5.items-center
input.grow.p-4.border-0.rounded-md.shadow-lg(class="w-7/8" type='text' placeholder='Search...' v-model='searchQuery')
button.bg-theme-primary.text-white.rounded-md.text-md.p-4(@click='fetchContacts') Search
.flex.flex-col.gap-2
label(for='showRemoved') Show Removed
input(name="showRemoved" type="checkbox" v-model="filters.showRemoved")
table.w-full.flex.flex-col.gap-2(v-if="searchResults.length")
thead
tr.grid.grid-cols-5.bg-white.rounded-lg.py-2
th Name
th Email
th Phone
th Company
th Actions
th(v-if="isEditor || isAdmin") Actions
tbody.flex.flex-col.gap-2
tr.grid.grid-cols-5.bg-white.rounded-lg.py-4(v-for='contact in searchResults' :key='contact.id')
p.text-center.align-center {{ (contact.firstName && contact.lastName) ? (contact.firstName + ' ' + contact.lastName) : (contact.firstName || contact.lastName || '') }}
p.text-center.align-center {{ contact.emailAddress ? contact.emailAddress : '' }}
p.text-center.align-center {{ contact.mainPhone ? contact.mainPhone : (contact.directPhone ? contact.directPhone : (contact.mobilePhone ? contact.mobilePhone : 'N/A')) }}
p.text-center.align-center {{ contact.company ? contact.company : '' }}
.flex.gap-5.justify-center
img.cursor-pointer.w-6.h-6(src='~/assets/edit-icon.png' alt='Edit Contact' @click="editContact(contact)")
img.cursor-pointer.w-6.h-6(src='~/assets/remove.png' alt='Remove' @click="confirmAction(contact, 'delete')")
.flex.gap-5.justify-center(v-if="isEditor || isAdmin")
img.cursor-pointer.w-6.h-6(v-if="!filters.showRemoved" src='~/assets/edit-icon.png' alt='Edit Contact' @click="editContact(contact)")
img.cursor-pointer.w-6.h-6(src='~/assets/remove.png' alt='Remove' @click="toggleArchived(contact)")
.flex.flex-col.gap-2.items-center.mt-10.select-none
.flex.gap-3.justify-center.mt-10
button.cursor-pointer.bg-zinc-100.p-2.rounded-md(class="disabled:bg-gray-300" @click="prevPage()" :disabled="currentPage === 0") Prev
Expand All @@ -56,15 +59,16 @@
<script lang='ts' setup>
import type { User } from '@/types.d';
import Multiselect from 'vue-multiselect';
//import VueDatePicker from '@vuepic/vue-datepicker';
import VueDatePicker from '@vuepic/vue-datepicker';
const selectedDateRange = ref('allcontacts');
const searchQuery = ref('');
const filters = ref({
startDate: new Date(0),
endDate: new Date(),
tag: []
tag: [],
showRemoved: false
});
const router = useRouter();
Expand All @@ -85,16 +89,18 @@ const totalPages = computed(() => {
return searchResults.value ? Math.ceil(count.value / pageSize.value) : 0;
});
const confirmAction = async (contact: any, action: string) => {
const toggleArchived = async (contact: any) => {
let confirmMessage;
confirmMessage = `Are you sure you want to remove ${contact.firstName} ${contact.lastName}?`;
if (!filters.value.showRemoved)
confirmMessage = `Are you sure you want to archive ${contact.firstName} ${contact.lastName}?`;
else
confirmMessage = `Are you sure you want to unarchive ${contact.firstName} ${contact.lastName}?`;
const confirmActionDialog = confirm(confirmMessage);
if (confirmActionDialog) {
const response = await $fetch(`/api/contactStatusChanger?contactId=${contact.id}&action=${action}`, {
const response = await $fetch(`/api/toggleArchived?contactId=${contact.id}&action=${filters.value.showRemoved ? 'unarchive' : 'archive'}`, {
method: 'PUT',
});
window.location.reload();
Expand Down Expand Up @@ -167,7 +173,8 @@ const constructQueryParams = () => {
searchQuery: searchQuery.value,
tag: tagsQueryParam,
cursor: cursors.value[currentPage.value] + '',
pageSize: pageSize.value + ''
pageSize: pageSize.value + '',
showRemoved: filters.value.showRemoved,
});
console.log("startdate with isostring", filters.value.startDate);
console.log("enddate with iostring", filters.value.endDate);
Expand Down
75 changes: 0 additions & 75 deletions pages/recoverContacts.vue

This file was deleted.

4 changes: 2 additions & 2 deletions server/api/contacts.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();

export default defineEventHandler(async (event) => {
const { pageSize, searchQuery, tag, startDate, endDate, cursor, showRemoved = false } = getQuery(event);
const { pageSize, searchQuery, tag, startDate, endDate, cursor, showRemoved } = getQuery(event);
const id = parseInt(cursor as string || "0")

const query: any = {
where: {
removed: showRemoved,
removed: showRemoved == "true",
AND: [],
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ export default defineEventHandler(async (event) => {
try {
let updatedContact;

if (action === 'recover') {
if (action === 'unarchive') {
// Update the contact by setting its removed field to false
updatedContact = await prisma.contact.update({
where: { id: parsedContactId },
data: { removed: false },
});
} else if (action === 'delete') {
} else if (action === 'archive') {
// Update the contact by setting its removed field to true
updatedContact = await prisma.contact.update({
where: { id: parsedContactId },
Expand Down

0 comments on commit 3bf1fe8

Please sign in to comment.